Dec-19-2019, 08:11 AM
It's a nested structure. The example will result in JSON object that is dict of dicts of dicts.
The most appropriate approach would depend on whether you know in advance what it looks like, e.g. how many levels, how many (i.e. one or many/undefined number) elements in each level.
Most generic approach:
The most appropriate approach would depend on whether you know in advance what it looks like, e.g. how many levels, how many (i.e. one or many/undefined number) elements in each level.
Most generic approach:
import json with open('sample.json') as json_file: data = json.load(json_file) for key, value in data.items(): print(f'key: {key}') for key2, value2 in value.items(): print(f'key2: {key2}') for key3, value3 in value2.items(): print(f'key3: {key3}') print(f'value3: {value3}') # in the example value3 is a list, i.e. you can iterate over/access it's elements
Output:key: domaine
key2: nom
key3: service
value3: ['test']
In my code I use generic key, key2, key3/value, bvalue2, value3 variable names. You better use more descriptive names if possible
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs