Projects

Encoding and Decoding Json #dd

Sept. 20, 2018, 9:49 p.m.

JSON(JavaScript Object Notation) encoding is used to convert the JSON into a string.

For Example -
>>> json.dumps(['koushik', {'dd': ('pam', None, 8.0, 2)}])
'["foo", {"koushik": ["dd", null, 8.0, 2]}]'

We can even PRETTY PRINT the strings using this function.
>>> import json
>>> print json.dumps({'1': 2, '5': 6}, sort_keys=True,vindent=4, separators=(',', ': '))
{
"1": 2,
"5": 6
}

JSON decoding is to convert the string to JSON format.
Look at this example -

>>> import json
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
[u'foo', {u'bar': [u'baz', None, 1.0, 2]}]