Read a json python

Code examples

54
0

python read json file

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)

print(data)
0
0

python read json file

import json
varRaw ='''
{
    "from":{
        "max" : "xx:xx:xx:xx:xx:xx",
        "ip" : "192.168.0.20"
    },
    "data":{
        "id":"value",
        "id": "value",
        "id": "value"
    }
}
'''
#string to json
varJson = json.loads(varRaw)
#get values from json

print(varJson['from'])
#output wil be: {'max': 'xx:xx:xx:xx:xx:xx', 'ip': '192.168.0.20'}
print(varJson['from']['ip'])
#output wil be: 192.168.0.20

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................