0

I have a simple question. I would like to use JSON file as following:

{
"data": {
    "1": {
        "id": 1, 
        "symbol": "A", 
        ...
        },
    }, 
    "1027": {
        "id": 1027, 
        "symbol": "B", 
        ...
        }, 
    },
    ...
}

It is from website, and I make a JSON file to parse such as tmp. I wanna see the result of tmp["data"]["1"]["symbol"], and there are 1000 data included. What I said is I would like to check tmp["data"]["1"]["symbol"] to tmp["data"]["1000"]["symbol"] with for statement. I cannot replace "1" part with another index number. Please help me out.

Thanks in advance.

2 Answers 2

1

This will output all the symbol values along with the corresponding ids:

for data in tmp['data'].values():
    print(data['id'], data['symbol'])
Sign up to request clarification or add additional context in comments.

Comments

1

For accessing all the sub-elements of data, try this -

for var in tmp['data'].values():
     print(var['symbol'])

This iterates for all the subelements of data and prints the symbol element in all the subelements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.