Posts Tagged ‘json’

Data serialization in python using Json.

September 7, 2010 Leave a comment

Serialization is helpful when we have many variables to store in the file (in example games) or we need to move it beetween programming languages.

JsonĀ  is text base serialization system, we can store (dump) data in-file and read it back. We need to remamber order of storing elements.

(Module named json is available in python 2.6 or greater)

import json
with open('basic.json', mode='w') as f:
 json.dump(basic_entry, f,indent=2)

with open('basic.json', mode='r') as f:
 print loaded

We got a file named basic.json

 "key": 10

Its very simple and flexible way to store many data in a file.

Categories: Uncategorized Tags: ,