Skip to main content
Version: 8.1

system.util.jsonEncode

This function is used in Python Scripting.

Description

Takes a Python object such as a list or dictionary and converts into a JSON string.

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

system.util.jsonEncode(pyObj, [indentFactor])

Parameters

TypeParameterDescription
AnypyObjThe Python object to encode into JSON such as a Python list or dictionary.
IntegerindentFactorThe number of spaces to add to each level of indentation for prettyprinting. [optional]

Returns

String - The encoded JSON string.

New in 8.1.28
**Float** - The encoded JSON value when encoding BigDecimal Java types.

Scope

Gateway, Vision Client, Perspective Session

JSON to Python Mapping

The table below lists possible Python types, and how they map to JSON objects.

JSON TypeMapped Python Type
Boolean (True/False)Boolean (true/false)
StringString
Number (Float, Integer)Numeric
Nonenull
SequenceArray
DictionaryObject

Code Examples

Example #1
# The following example builds a Python dictionary, and converts it to a JSON string

# Build the Python dictionary
employeeDict = {"employees":[{"firstName":"John", "lastName":"Doe"},{"firstName":"Anna", "lastName":"Smith"},{"firstName":"Peter", "lastName":"Jones"}]}

# Convert the dictionary and store the resulting JSON string in a variable.
jsonString = system.util.jsonEncode(employeeDict)

Keywords

system util jsonEncode, util.jsonEncode