Tuesday, March 22, 2016

json in python

http://docs.python-guide.org/en/latest/scenarios/json/

-json library is simple: A. converts python dictionary to json string, B. json string to python dictionary

-two importand methods: A. loads(json_string) to create regular python dictionary, B. dumps(python_dictionary)

-difference between json string and python dictionary: They are very similar. json string is a standard JavaScript Object Notation string which must include the outer curly braces as part of the string. In python dictionary the outer curly braces are reserved python keyword:

Example:

python dictionary: {'age':12}
json string            : '{'age':12}'

Only difference: single quote around python dictionary in json string
Though only difference is, the quote - json is universal format, but json type dictionary is python specific.

Internal mechanism: conversion between json and dictionary:



Note: if you find 'u' in json string - this only means the content is unicode




 

No comments:

Post a Comment