Convert Dictionary To JSON
PUBLISHED ON JANUARY 3, 2020
Last updated
PUBLISHED ON JANUARY 3, 2020
Last updated
This python tutorial help to convert Python Dictionary To JSON. The JSON is very popular format to exchange data between server and client.
The python dictionary is a collection which is unordered, changeable and indexed.We will convert dict collection in json format.
We will take simple dict and stored string key:value
pair.We will stored employee data into dict object.
The python Dictionary is an unordered collection of data values, that store the data values like a map. The dictionary holds key:value pair.The key can be hold only single value as an element.Keys of a Dictionary must be unique and of immutable data type such as Strings, Integers and tuples.HTML
The python has json package to handle and process json data.The process of encoding the JSON is usually called the serialization.The deserialization is a reciprocal process of decoding data that has been stored or delivered in the JSON standard.The json.dumps()
method is used to convert dict to json string.HTML
We have defined one empDict dictionary and then convert that dictionary to JSON using json.dumps()
method.This method also accept sort_keys as the second argument to json_dumps().This help to sort the dictionary against keys.HTML
Reference : https://www.pythonpip.com/python-tutorials/convert-python-dictionary-to-json/