python json serialize object

Solutions on MaxInterview for python json serialize object by the best coders in the world

showing results for - "python json serialize object"
Hillary
11 Feb 2019
1import json
2info = {
3    "data": {
4        "name": "Dave",
5        "City": "NY"
6    }
7}
8# With json.dump  (into file)
9with open( "data.json" , "w" ) as x:
10    json.dump( info , x )
11# >>> {"data": {"name": "Dave", "City": "NY"}}
12
13# with json.dumps (object)
14data = json.dumps( info )
15print( data )
16# >>> {"data": {"name": "Dave", "City": "NY"}}