You are here: Jython Script Interfaces > JSON module

JSON module

 

Parsing and serializing JSON is done with a Python module named "json". You need to add an "import json" line to your code in order to use it. This module provides two key functions - "loads" and "dumps", which stand for "load string" and "dump string" respectively.

 

This is an example of how to use the "loads" and "dumps" functions:

 

import json
input_string = '{"x":"y"}'
parsed_object = json.loads(input_string)
print parsed_object['x'] # This will print 'y' to the logs.
parsed_object['z'] = 1
output_string = json.dumps(parsed_object)
print output_string # This will print '{"x": "y", "z": 1}' to the logs.

 

The json module in MD Link is backed by the third-party "simplejson" project. For more information on the "loads" and "dumps" functions, and on other functions in this module, see the simplejson documentation here.