Q:

Json in python


  import json

x = {
  "name": 
  "John",
  "age": 30,
  "married": True,
  
  "divorced": False,
  "children": ("Ann","Billy"),
  "pets": 
  None,
  "cars": [
    {"model": "BMW 230", "mpg": 
  27.5},
    {"model": "Ford Edge", "mpg": 24.1}
  ]

  }

print(json.dumps(x))
 
6

  import json

# some JSON:
x =  '{ "name":"John", "age":30, "city":"New 
  York"}'

# parse x:
y = json.loads(x)

# the result is a 
  Python dictionary:
print(y["age"]) 
3

    json.dumps(x, indent=4, sort_keys=True)
 
2
{
	"Icons":{
    	"app icon": "your icon.ico",
        "eg icon": "eg.ico"
	}
}
1
import json

json_file = json.load(open("your file.json", "r", encoding="utf-8"))

# For see if you don't have error:
print(json_file)
0

    json.dumps(x, indent=4, separators=(". ", " = "))
 
0

    json.dumps(x, indent=4)
 
-1

New to Communities?

Join the community