Json (JavaScript Object Notation) is a text based data exchange format widely used in porting data to different languages and platforms. All most all programming languages have libraries to manage Json.
Here are some common methods used for managing Json strings.
Serializing JSON:
We can use a set of data in python and convert or encode them to Json string. Python objects in the form of of list, dictionary , string , integer etc can be converted by using dumps().
json.dumps() : to convert Python objects to Json string ( Serializing ) json.dump() : to convert Python object to Json to use along with file object.
Following Python objects can be converted to respective Json format.
Python
Json
Dictionary
Object
list, Tuple
Array
String , Unicode
String
int, long, float
Number
True
true
False
false
None
null
Deserializing
Data or string in the Json format can be decoded to get the objects in Python.
json.loads() : to convert Json data to Pyton Object ( Deserializing ) json.load() : converting Json data from file to Python object by using file object.
Here is a list of Json data which can be converted to Python objects.
Json
Python
Object
Dictionary
Array
List
string
Unicode
Number (int )
int , long
Number ( real )
float
true
True
false
False
null
None
MySQL Database records and Json format.
As the main requirement of Json is data exchange, here is the code to collect data from mysql table and then encode the same to get the data in Json format.