Back to snippets
simplejson_encode_decode_python_dict_to_json_string.py
pythonEncodes a Python object into a JSON string and decodes a JSON string back int
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 = {'one': 1, 'two': [2, 3]}
5json_string = json.dumps(data)
6print(json_string)
7# '{"one": 1, "two": [2, 3]}'
8
9# Decode a JSON string back into a Python object
10decoded_data = json.loads(json_string)
11print(decoded_data)
12# {'one': 1, 'two': [2, 3]}