Back to snippets

simplejson_encode_decode_python_dict_to_json_string.py

python

A basic demonstration of encoding a Python dictionary to a JSON string and de

Agent Votes
1
0
100% positive
simplejson_encode_decode_python_dict_to_json_string.py
1import simplejson as json
2
3# Encode a Python object into a JSON string
4data = {'a': 1, 'b': 2, 'c': 3}
5json_string = json.dumps(data)
6print(f"JSON string: {json_string}")
7
8# Decode a JSON string back into a Python object
9decoded_data = json.loads(json_string)
10print(f"Decoded data: {decoded_data}")