--- title: "Object to JSON" slug: "core-json-encode-resolver" updated: 2026-04-15T12:13:23Z published: 2026-04-15T12:13:23Z canonical: "docs.lobstersoftware.com/core-json-encode-resolver" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.lobstersoftware.com/llms.txt > Use this file to discover all available pages before exploring further. # Object to JSON *See also:* [JSON to object](/v1/docs/en/core-json-decode-resolver) > [!NOTE] > Value resolver – Abstract > > **Purpose:** Returns the data structure of the *input value* as text in JSON notation. > > > [!TIP] > > Tooltip > > > > - **Usage**: The value resolver returns the data structure of the *input value* as text in JSON notation. > > - **Parameters:** > > - The optional **Class field name** parameter can be set differently from the default (`class`) if needed. > > - The **Enforce native types** option enforces the use of native JSON data types, e.g. `Number` for numerical values and `Array` for lists. > > - **NOTE:** If the **Class field name** is empty, the class name is written into a property without a name (`""`) (see information on restrictions for objects with *unlabeled properties* in the manual entry). ![images/download/attachments/119247376/image2023-1-4_16-33-12-version-1-modificationdate-1672846392970-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2023-1-4_16-33-12-version-1-modificationdate-1672846392970-api-v2.png) The [Object to JSON](/v1/docs/en/core-json-encode-resolver) resolver returns the data structure of the input value as text in JSON notation (see [JSON data encoder](/v1/docs/en/core-json-data-encoder)). **NOTE:** If the *input value* is "No value" (`$null`), the text `null` is output. - The **Class field name** parameter defines the name of the property to be used in the output format to declare the "class" of objects. - The **Enforce native types** option (unchecked by default) enforces the use of native JSON data types, e.g. `Number` for numerical values and `Array` for lists. > [!NOTE] > Details on the effect of the "Enforce native types" option > > --- > > Example: > > The "Roles" (`roles`) field of a user account (see [Users](/v1/docs/en/base-user)) is defined as a "Set" (`Set`), since the same user should be able to be assigned only the same role a maximum of once. The assigned roles are referenced in this list by their ID (`id`), which is by definition an integer of the `Long` type. The value of the `roles` field is therefore a `Set` of `Long` values. The following table illustrates the effect of checking or unchecking the **Enforce native types** option when creating a JSON string that reflects the value of the roles (`roles`) field: > > | "Enforce native types" option | Return value (JSON string) | > | --- | --- | > | ![images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/error.svg](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/error(25).svg) unchecked (*Default*) | ```json { "class": "set", "data": [ { "class": "java.lang.Long", "value": "1" },{ "class": "java.lang.Long", "value": "501" },{ "class": "java.lang.Long", "value": "1001" } ] } ``` | > | ![images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/check.svg](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/check(31).svg) checked | ```plaintext [ 1, 501, 1001 ] ``` | > > **NOTE:** Since the **Enforce native types** option maps different data types used in **Lobster Data Platform/Orchestration** to the same JSON data type, information (about the data type) can get lost. > > In the example, the return value with the checked option no longer contains the information that the list as a `Set` can only contain unique values and that the contained values are by definition of the `Long` type. ## Configuration An object is expected as *input value*. The **Class field name** parameter allows the input of a static text as a [Text field](/v1/docs/en/custom-custom-text-field), which is used in the output format to declare the "class" of objects within the JSON document. The *default value* is the `class` string. If no **Class field name** is specified, the class name is written as the value of a property named Empty string (`""`). **NOTE:** A structure with a property containing an e*mpty string* ("") can also be parsed again using the [JSON to object](/v1/docs/en/core-json-decode-resolver) value resolver. If the **Class field name** is not empty (e.g. `class`), a client object is created that contains the class name in an *unlabeled property*. A `Long` value (1343) as *input value* then becomes a client object with the following JSON structure: | {"":"java.lang.Long", "value":"1343"} | | --- | The value (1343) can still be taken from the `value` property as a string. The class name is contained – also as a string – in the *unlabeled property*. However, for a client object with an unlabeled property, the following restrictions must be considered: 1. The *unlabeled property* can no longer be accessed directly – e.g. via [Object property](/v1/docs/en/core-property-resolver) value resolver, via [get (Read value from data field)](/v1/docs/en/calc-function-get) or as a data field (for [Form elements](/v1/docs/en/fre-form-elements)). 2. Trying to encode a client object with an *unlabeled property* into a client XML structure (e.g. via [Object to client xml](/v1/docs/en/core-client-xml-encode-resolver) or [Object to server xml](/v1/docs/en/core-server-xml-encode-resolver)) fails with the error (`Failed to encode`: `INVALID_CHARACTER_ERR`), because the *encoder* tries to create an XML element with the name `""`. **NOTE:** The [Object to server xml](/v1/docs/en/core-server-xml-encode-resolver) value resolver, on the other hand, maps the *unlabeled* *properties* to a `property` with `name=""` without any problems. The **Enforce native types** option controls the handling of certain data types (numerical values and lists) in the output for which no 1:1 image exists in JSON format. - If the **Enforce native types** option is unchecked (default), then the data types in question are output as data objects with an explicit class field if required. - If the **Enforce native types** option is checked, data of the respective data types will be mapped to the corresponding native JSON data type (`Number` or `Array`), which can simplify the output format (see info box above). ## Examples *The screenshots in the following table do not show the* ***Enforce native types*** *option. The table contains corresponding notes as far as a selection of this option influences the displayed return value at all.* | Input value | Configuration example | Return value (string) | | --- | --- | --- | | Text (for the server one `any` object with `string` value) | ![images/download/attachments/119247376/image2022-6-20_17-1-59-version-1-modificationdate-1669201068956-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2022-6-20_17-1-59-version-1-modificationdate-1669201068956-api-v2.png) | `"HELLO WORLD!"` | | Date/Time (`DateTime` object) | ![images/download/attachments/119247376/image2022-6-20_17-3-58-version-1-modificationdate-1669201068947-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2022-6-20_17-3-58-version-1-modificationdate-1669201068947-api-v2.png) | ```json { "class": "de.lobster.scm.utils.date.DateTime", "dateValue": "1655735288548", "timeZone": "UTC" } ``` | | or with ![images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/check.svg](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/check(31).svg) **Enforce native type** option: ```json { "class": "de.lobster.scm.utils.date.DateTime", "dateValue": 1655735288548, "timeZone": "UTC" } ``` | | Heterogeneous list of values (one `list` object with possibly different types per `entry`) | ![images/download/attachments/119247376/image2022-6-20_17-5-21-version-1-modificationdate-1669201068935-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2022-6-20_17-5-21-version-1-modificationdate-1669201068935-api-v2.png) | ```json { "class": "list", "data": [ { "class": "java.lang.Long", "value": "4711" }, "0815" ] } ``` | | or with ![images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/check.svg](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/check(31).svg) **Enforce native type** option: ```plaintext [ 4711, "0815" ] ``` | | Company account (as an example of an entity) | ![images/download/attachments/119247376/image2022-6-20_17-8-9-version-1-modificationdate-1669201068928-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2022-6-20_17-8-9-version-1-modificationdate-1669201068928-api-v2.png) --- **NOTE:** Setting the **Enforce native types** option, which is unchecked by default, would result in the following differences for the excerpt from the return value shown on the right: - The field values for `creatorId`, `lastModifierId` and `ownerId` would be output as integers and no longer as strings ("..."). - The field value for `parentCompanies` would be output as a list of integers (*here*: with only one entry) and no longer as a list of long objects: `"parentCompanies": [ 702 ]` | ```json { "class": "de.lobster.scm.base.company.CompanyAccount", "address": { ... }, "attributes": [ ... ], "created": { "time": "1536306221204", "nanos": 204000000 }, "creatorId": "1901", "defaultTimeZone": null, "id": "1902", "lastModified": { "time": "1651765029218", "nanos": 218000000 }, "lastModifierId": "1901", "locale": "en", "metaType": "COMPANY", "ownerId": "702", "parentCompanies": [ { "class": "java.lang.Long", "value": "702" } ], "partialLoaded": false, "styleName": "XFLOW", "types": [ { "class": "de.lobster.scm.denum.DynamicEnumDto", "enumName": "de.lobster.scm.base.company.CompanyType", "name": "FWD" }, { "class": "de.lobster.scm.denum.DynamicEnumDto", "enumName": "de.lobster.scm.base.company.CompanyType", "name": "CNE" }, { "class": "de.lobster.scm.denum.DynamicEnumDto", "enumName": "de.lobster.scm.base.company.CompanyType", "name": "AAL" }, { "class": "de.lobster.scm.denum.DynamicEnumDto", "enumName": "de.lobster.scm.base.company.CompanyType", "name": "DPA" }, { "class": "de.lobster.scm.denum.DynamicEnumDto", "enumName": "de.lobster.scm.base.company.CompanyType", "name": "INV" } ] } ``` `}` |