JSON in Python

 

v  JSON in Python: -

  • JSON stands for JavaScript Object Notation, which is a format for structuring data.

  • It is a widely used data format for storing and transferring data between a client and a server system.

  • It can be used with various programming languages such as Python, Perl, Java, etc.

  • Python supports JSON through a built-in package called Json. To use this feature, we import the JSON package in Python.

  •  The text in JSON is done through quoted strings, which contain the value in key-value mapping within { }, which is similar to a dictionary in Python.

  • JSON supports primitive types like numbers, strings, lists, nested lists, tuples and objects.

  • In Python, we can convert Python objects (like dictionaries and lists) into JSON strings; this process is called serialisation and also parse JSON data back into Python objects; this process is called deserialisation.

  • Python provides the following important methods in the JSON module:

1.      dump( )

2.      load( )

3.      dumps( )

4.      loads( )


1)    dump( ): -The json.dump( ) method is used to write a Python object to JSON data into a file.

Example                                                                                       





















                      output
 

2)    load( ): -json.load( ) method is used to read JSON data from a file and convert it into a Python object.

Example



Output: -

3)    dumps( ): -  json.dumps( ) method is used to convert a Python object like a dictionary or list into a JSON-formatted string.

Example                      


 
  output


4)  loads( ): - json.loads( ) method is used to convert a JSON string into a Python object.

Example                                                                                             


Output  

Popular posts from this blog

operators in c programming

Variables in c

Cloud Storage and Local Storage: Applications in Business