JSON to object

See also: Object to JSON

Value resolver – Abstract

Purpose: Parses a string provided as input value as a JSON structure to return an object.


images/download/attachments/106955200/EN_title_0-version-1-modificationdate-1655312828447-api-v2.PNG

The Objekt aus Server XML erzeugen value resolver parses a string passed as input value as JSON to return an object.

The following cases are differentiated:

Input value (abstract)

Input value (specific examples)

Return value

Error

No value ($null)

No value ($null)

No value ($null)

n/a

A string that violates the rules of the JSON notation

Empty string ("")


{fieldName:=fieldValue}

n/a

ProcessException:Failed to parse

A string that conforms to the rules of the JSON notation







null

No value ($null)

n/a

"null"

Null (String)

n/a

1.5e3

1500.0 (Double)

n/a

[ABC,123,true,null]

An array or list with four elements: ABC (string), 123 (long), true (Boolean), no value ($null)

n/a

{"msg":"Hello World!"}

A client object with an msg property containing the "Hello World!" string

n/a

{"class":"de.lobster.scm.scem.incident.Incident","id":666,"name":"doom","incidentSeverity":"HIGH"}

NOTE◄ The 'volatile entity' created from this JSON structure (see 'Return value' column, right) can be saved using the Save changes later event action, for example, to create the entity server-side. However, this only works if the ID 666 is not yet in use.

WARNING◄ The assignment of IDs for new entities should definitely be left to the Lobster Data Platform / Orchestration server by assigning the ID 0. Then the entity is automatically assigned a new ID when it is saved. Interventions in the assignment of IDs – especially by assigning IDs in the area of the number range that has not yet been used – can result in conflicts in later write operations.

If the appropriate Class field name class is used:

A 'volatile' entity of the "Incident" type (see SCEM Incident) with ID 666 and severity HIGH, but without the 'name' property, which is not provided for in the data model of the class (Incident):

{
"class": "de.lobster.scm.scem.incident.Incident",
"affectedEntities": null,
"created": null,
"creatorId": "0",
"id": "666",
"incidentSeverity": "HIGH",
"incidentSource": null,
"incidentState": null,
"incidentType": null,
"lastModified": null,
"lastModifierId": "0",
"ownerId": "0",
"partialLoaded": false,
"temporaryValues": null
}

(Entity data in JSON notation)

NOTE◄ In the JSON notation, the values of properties that are Long values by definition in the Incident class data model appear as strings (between apostrophes). This example concerns the id, creatorId, lastModifierId and ownerId properties.


If the Class field name is inappropriate (e.g. ignoreClass), a client object is returned containing all data of the input value, i.e. also a class property with the class name for SCEM Incident:

{
"name": "doom",
"incidentSeverity": "HIGH",
"id": {
"clazz": "java.lang.Integer",
"value": 666
},
"class": "de.lobster.scm.scem.incident.Incident"
}

(Data of the client object in JSON notation)

NOTE◄ This JSON structure was created with the Object to JSON value resolver. For demonstration purposes, the value clazz was used for the parameter Class field name, deviating from the default (class). This allows a distinction to be made between the class property that actually existed in the generated client object and the name clazz that was added when decoding the Long value (666) for the JSON output of the id property.

n/a

Configuration

Parameter

Meaning

Class field name

The parameter defines a property name that can be used within the JSON string to identify the class of an object.
The class property is used by default (see example above).

Parse array as a list

This option is selected by default, so that an array (in the input value) is converted into a 'list' object (List).

Example

In the context of an event handling, the user should be able to enter a comma-separated list of values via User prompt, the total of which is subsequently calculated.

Runtime example:

images/download/attachments/106955200/image2022-6-20_12-15-20-version-1-modificationdate-1655720120706-api-v2.png

  • A discount of 10% (-250) is deducted from a list price of 2500 (25 x 10²) and a handling fee of 12.5 is added. Result:

    images/download/attachments/106955200/image2022-6-20_12-15-45-version-1-modificationdate-1655720145927-api-v2.png

Configuration:

The JSON to object value resolver is used here to demonstrate 'resolving' the text value from the User prompt into a list of individual values.

The surrounding Concat strings value resolver encloses the user's input in square brackets ([ ... ]) for this purpose. Provided that the input is a comma-separated list of strings that can be interpreted as numeric values (see example), the expression as a whole results in a text that defines a list of numeric values in JSON format.

The User prompt is used in conjunction with the Concat strings and the chained JSON to object value resolver directly to define the Resolver for entities parameter in a For each loop event action.

The loop iterates over the entered scalar values and adds them successively via Calculate value value resolver in the variable total. The scalar value is included in the calculation via the variable increment.

After the loop has been completed, the amount can be read from the total variable. It is output here via Show alert (Popup).

IMPORTANT◄ In addition to the configuration shown here, the variable total should be explicitly assigned the value 0 before the start of the loop. Otherwise, a possible value already present can falsify the result.

images/download/attachments/106955200/image2022-6-20_12-17-29-version-1-modificationdate-1655720249635-api-v2.png