I have dynamic jSON that could contain keys and subkeys.
Since each jSON could have more or less keys/subkeys (some of they may or not appear), I'd like to iterate the Object and get all information (key and value). My problem is this iteration since I don't see how can I achieve this.
Dim JSON_Obj1 As Object = New JavaScriptSerializer().DeserializeObject(JSON_Response)
When trying to access data:
For Each j In JSON_Obj1
Console.WriteLine(j.ToString)
Next
This code outputs the data like:
If it's a key:
[id, 130ee895-1e5e-4f82-bb66-e1275bac75dd]
if it's a subkey:
[image_uris, System.Collections.Generic.Dictionary`2[System.String,System.Object]]
After checking my j var, I don't have many options that could get that information.
How can I achieve this automatically, without need to make checks if keys exists and retrieve their value and key name?
Edit: Added 2 jSON example
{
"object": "card",
"id": "3606519e-5677-4c21-a34e-be195b6669fa",
"oracle_id": "35ae7b25-6d0f-49f8-a40d-dd2cf88e6f44",
"multiverse_ids": [
503627,
503626
],
"mtgo_id": 87365,
"arena_id": 75057,
"tcgplayer_id": 230921,
"cardmarket_id": 532112,
"name": "Reidane, God of the Worthy // Valkmira, Protector's Shield",
"lang": "en",
"released_at": "2021-02-05",
"uri": "https://api.scryfall.com/cards/3606519e-5677-4c21-a34e-be195b6669fa",
"scryfall_uri": "https://scryfall.com/card/khm/21/reidane-god-of-the-worthy-valkmira-protectors-shield?utm_source=api",
"layout": "modal_dfc",
"highres_image": false,
"cmc": 3.0,
"type_line": "Legendary Creature — God // Legendary Artifact",
"color_identity": [
"W"
],
"keywords": [
"Flying",
"Vigilance"
],
"card_faces": [
{
"object": "card_face",
"name": "Reidane, God of the Worthy",
"mana_cost": "{2}{W}",
"type_line": "Legendary Creature — God",
"oracle_text": "Flying, vigilance
Snow lands your opponents control enter the battlefield tapped.
Noncreature spells your opponents cast with converted mana cost 4 or greater cost {2} more to cast.",
"colors": [
"W"
],
"power": "2",
"toughness": "3",
"artist": "Jason Rainville",
"artist_id": "6ed7e669-579b-443d-b223-e5cbcb2a7483",
"illustration_id": "50842425-89ab-475d-afce-b43b28f9aa43",
"image_uris": {
"small": "https://c1.scryfall.com/file/scryfall-cards/small/front/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242",
"normal": "https://c1.scryfall.com/file/scryfall-cards/normal/front/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242",
"large": "https://c1.scryfall.com/file/scryfall-cards/large/front/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242",
"png": "https://c1.scryfall.com/file/scryfall-cards/png/front/3/6/3606519e-5677-4c21-a34e-be195b6669fa.png?1611000242",
"art_crop": "https://c1.scryfall.com/file/scryfall-cards/art_crop/front/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242",
"border_crop": "https://c1.scryfall.com/file/scryfall-cards/border_crop/front/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242"
}
},
{
"object": "card_face",
"name": "Valkmira, Protector's Shield",
"mana_cost": "{3}{W}",
"type_line": "Legendary Artifact",
"oracle_text": "If a source an opponent controls would deal damage to you or a permanent you control, prevent 1 of that damage.
Whenever you or a permanent you control becomes the target of a spell or ability an opponent controls, counter that spell or ability unless its controller pays {1}.",
"colors": [
"W"
],
"artist": "Jason Rainville",
"artist_id": "6ed7e669-579b-443d-b223-e5cbcb2a7483",
"illustration_id": "d8a037ea-c67b-4290-81ef-cdb8073c46cb",
"image_uris": {
"small": "https://c1.scryfall.com/file/scryfall-cards/small/back/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242",
"normal": "https://c1.scryfall.com/file/scryfall-cards/normal/back/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242",
"large": "https://c1.scryfall.com/file/scryfall-cards/large/back/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242",
"png": "https://c1.scryfall.com/file/scryfall-cards/png/back/3/6/3606519e-5677-4c21-a34e-be195b6669fa.png?1611000242",
"art_crop": "https://c1.scryfall.com/file/scryfall-cards/art_crop/back/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242",
"border_crop": "https://c1.scryfall.com/file/scryfall-cards/border_crop/back/3/6/3606519e-5677-4c21-a34e-be195b6669fa.jpg?1611000242"
}
}
],
"legalities": {
"standard": "legal",
"future": "legal",
"historic": "legal",
"gladiator": "legal",
"pioneer": "legal",
"modern": "legal",
"legacy": "legal",
"pauper": "not_legal",
"vintage": "legal",
"penny": "not_legal",
"commander": "legal",
"brawl": "legal",
"duel": "legal",
"oldschool": "not_legal",
"premodern": "not_legal"
},
"games": [
"arena",
"paper",
"mtgo"
],
"reserved": false,
"foil": true,
"nonfoil": true,
"oversized": false,
"promo": false,
"reprint": false,
"variation": false,
"set": "khm",
"set_name": "Kaldheim",
"set_type": "expansion",
"set_uri": "https://api.scryfall.com/sets/43057fad-b1c1-437f-bc48-0045bce6d8c9",
"set_search_uri": "https://api.scryfall.com/cards/search?order=set&q=e%3Akhm&unique=prints",
"scryfall_set_uri": "https://scryfall.com/sets/khm?utm_source=api",
"rulings_uri": "https://api.scryfall.com/cards/3606519e-5677-4c21-a34e-be195b6669fa/rulings",
"prints_search_uri": "https://api.scryfall.com/cards/search?order=released&q=oracleid%3A35ae7b25-6d0f-49f8-a40d-dd2cf88e6f44&unique=prints",
"collector_number": "21",
"digital": false,
"rarity": "rare",
"card_back_id": "0aeebaf5-8c7d-4636-9e82-8c27447861f7",
"artist": "Jason Rainville",
"artist_ids": [
"6ed7e669-579b-443d-b223-e5cbcb2a7483"
],
"border_color": "black",
"frame": "2015",
"frame_effects": [
"legendary"
],
"full_art": false,
"textless": false,
"booster": true,
"story_spotlight": false,
"edhrec_rank": 15706,
"preview": {
"source": "Marty Friedman",
"source_uri": "https://twitter.com/marty_friedman/status/1349527247560994816",
"previewed_at": "2021-01-13"
},
"prices": {
"usd": "0.87",
"usd_foil": "5.68",
"eur": "1.37",
"eur_foil": "2.00",
"tix": null
},
"related_uris": {
"gatherer": "https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=503627",
"tcgplayer_decks": "https://decks.tcgplayer.com/magic/deck/search?contains=Reidane%2C+God+of+the+Worthy&page=1&utm_campaign=affiliate&utm_medium=api&utm_source=scryfall",
"edhrec": "https://edhrec.com/route/?cc=Reidane%2C+God+of+the+Worthy",
"mtgtop8": "https://mtgtop8.com/search?MD_check=1&SB_check=1&cards=Reidane%2C+God+of+the+Worthy"
},
"purchase_uris": {
"tcgplayer": "https://shop.tcgplayer.com/product/productsearch?id=230921&utm_campaign=affiliate&utm_medium=api&utm_source=scryfall",
"cardmarket": "https://www.cardmarket.com/en/Magic/Products/Singles/Kaldheim/Reidane-God-of-the-Worthy-Valkmira-Protectors-Shield?referrer=scryfall&utm_campaign=card_prices&utm_medium=text&utm_source=scryfall",
"cardhoarder": "https://www.cardhoarder.com/cards/87365?affiliate_id=scryfall&ref=card-profile&utm_campaign=affiliate&utm_medium=card&utm_source=scryfall"
}
}
Example 2:
{
"object": "card",
"id": "03595195-3be2-4d18-b5c0-43b2dcc1c0f5",
"oracle_id": "eeb07c8a-21d1-43fa-a5f3-ee3fe328a671",
"multiverse_ids": [
503625
],
"mtgo_id": 87361,
"arena_id": 75056,
"tcgplayer_id": 230200,
"cardmarket_id": 530517,
"name": "Rally the Ranks",
"lang": "en",
"released_at": "2021-02-05",
"uri": "https://api.scryfall.com/cards/03595195-3be2-4d18-b5c0-43b2dcc1c0f5",
"scryfall_uri": "https://scryfall.com/card/khm/20/rally-the-ranks?utm_source=api",
"layout": "normal",
"highres_image": false,
"image_uris": {
"small": "https://c1.scryfall.com/file/scryfall-cards/small/front/0/3/03595195-3be2-4d18-b5c0-43b2dcc1c0f5.jpg?1610585956",
"normal": "https://c1.scryfall.com/file/scryfall-cards/normal/front/0/3/03595195-3be2-4d18-b5c0-43b2dcc1c0f5.jpg?1610585956",
"large": "https://c1.scryfall.com/file/scryfall-cards/large/front/0/3/03595195-3be2-4d18-b5c0-43b2dcc1c0f5.jpg?1610585956",
"png": "https://c1.scryfall.com/file/scryfall-cards/png/front/0/3/03595195-3be2-4d18-b5c0-43b2dcc1c0f5.png?1610585956",
"art_crop": "https://c1.scryfall.com/file/scryfall-cards/art_crop/front/0/3/03595195-3be2-4d18-b5c0-43b2dcc1c0f5.jpg?1610585956",
"border_crop": "https://c1.scryfall.com/file/scryfall-cards/border_crop/front/0/3/03595195-3be2-4d18-b5c0-43b2dcc1c0f5.jpg?1610585956"
},
"mana_cost": "{1}{W}",
"cmc": 2.0,
"type_line": "Enchantment",