python dict to json
snippet in javascript

python dictionary to json

user1256

import json

appDict = {
  'name': 'messenger',
  'playstore': True,
  'company': 'Facebook',
  'price': 100
}
app_json = json.dumps(appDict)
print(app_json)

python dict into json string

user3712

import json   
# Data to be written
dictionary ={   
  "A": 5,   
  "B": "guys",   
}

# Serializing json
json_object = json.dumps(dictionary, indent = 4)   
print(json_object)
# Output
{
    "A": 5,
    "B": "guys",
}

python dict to json

user5392

# app.py

import json

appDict = {
  'name': 'messenger',
  'playstore': True,
  'company': 'Facebook',
  'price': 100
}
app_json = json.dumps(appDict)
print(app_json)

python json to dict

user6750


  import json

# some JSON, could be a file opening :
x =  '{ "name":"John", "age":30, "city":"New 
  York"}'

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

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

convert dictionsr to json file python

user3390

import json 
# Data to be written 
dictionary ={ 
	"name" : "sathiyajith", 
	"rollno" : 56, 
	"cgpa" : 8.6, 
	"phonenumber" : "9976770500"
} 
with open("sample.json", "w") as outfile: 
	json.dump(dictionary, outfile) 

convert dict to json python

user8108

import json
with open('result.json', 'w') as fp:
    json.dump(sample, fp)