Processing Character Strings in JSON Format

SAP Plant Connectivity can serialize data objects into a character string with JSON-compliant notation. In other words, it can convert a structured data object into a sequential display format in JSON format. The conversion is also supported in the opposite direction: A data object can be deserialized from a character string in JSON notation

JSON stands for JavaScript Object Notation. The data objects can have elementary, structured, array, or enumeration data types and be nested to any depth. Circular references of objects and data types are not supported.

Serialized objects can be used, for example, to process text files using the file system source system in which business objects, such as machine or order data, is available in a structured text form. An additional example of this application is the transfer of structured data to SAP MII using JSON-formatted character strings.

To generate a JSON character string from a data object, use the function toJson(). The counterpart is the function fromJson() for generating a data object with a specific target data type from a JSON character string.

The various PCo data type categories are serialized and deserialized as follows:

  • Data objects of elementary data types are displayed as a character string in a culture-independent format.

  • A structured object is displayed as an unordered list of properties and values, for example:

    In addition, the JSON character string can contain information about the PCo data types of the structured objects. In the function toJson(), you define the name of a property that denotes the type information, for example, "__type".

    To be able to deserialize a structured data object with a specific PCo data type from a JSON character string, the function fromJson() also needs the type information property to be specified.

  • Arrays are displayed as an ordered list of elements separated by commas. The following example shows an array consisting of two elements that represent structured data objects with type information:

  • Data objects that are represented within PCo as “list”, for example, an object that was generated by the function emptylist, are converted like arrays into a JSON character string.

  • Data objects that are represented within PCo as “map”, for example, an object that was generated using the function emptymap, are converted like arrays from key-value pairs into a JSON character string. The key of a map entry is denoted with the property key, the value with the property value.

    Example: