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.
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: { (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: { (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. |
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:
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:
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. |
|