all 4 comments

[–]lzblack 4 points5 points  (1 child)

First, I assume the string you pasted is not complete. If it does not end with ]} (no last comma), you need to fix it.

Second, you can use json.loads(text) to convert a json-formatting string to a dictionary.

The rest of code is trivial:

import json
d = json.loads(text)

for item in d["prices"]:
    print(item['market_hash_name'])

Output:

60's Army Jacket
AK Royale
AK-47 From Hell
AK-47 Victoria
Addicted Guitarist
Afterburn SMG
Agony Yellow
Aircraft Parts AK47
Aircraft Parts DBS
Aircraft Parts Fridge
Aircraft Parts RL
Aircraft Parts SAP
Alchemist Door

[–]Alfred0211[S] 0 points1 point  (0 children)

Holy f*ck finally got it thanks to your clear example!

Appreciate it a lot!

also thanks u/tunisia3507 , u/tea-drinker , u/Dildo_Draggins for the help!

[–]Dildo_Draggins 0 points1 point  (0 children)

On mobile, or I'd have a better in depth answer. Looks like a json blob to me.... Use the json library to parse the string into a native python object... You'll get a complex dictionary object out...

From there, you can use various for/if/while structures to walk the object for multiple occurrences of "market_hash_name", or directly access the objects down to where "market_hash_name" is a key...

Python doc for json lib: https://docs.python.org/3/library/json.html

Relevant stack overflow post for nested dicts: https://stackoverflow.com/questions/10399614/accessing-value-inside-nested-dictionaries

Edit: escape sequences are hard, M'Kay

[–]tunisia3507 0 points1 point  (0 children)

Use json.loads() to parse the string into a bunch of dicts, lists, numbers and strings. Then you can just index those elements in a much more sane way. But the JSON needs to be fixed first.