Set or Change a JSON's Value

Sets or changes a specific value within a JSON object to a new value.

Overview

This procedure sets or changes a specific value within a JSON object to a new value. The verbs "set" and "change" are interchangeable. It supports both simple field names and nested paths using dot notation (e.g., settings.notifications.enabled). If the field does not exist, it will be created. The JSON object is modified in place.

Input

Concept
Type
Description
Required
Default

json

json

The JSON object to be modified

Yes

N/A

thing

string

The path within the JSON object where the value is to be set or changed (specified as a handle)

Yes

N/A

target

any

The new value to be set at the specified path within the JSON object

Yes

N/A

Output

This procedure modifies the JSON in place and does not return a value.

Examples

1. Setting a simple field value

This example sets the "age" field of the JSON object to 23.

get the json
the json's age is 23

2. Setting a field using the set command

This example sets the "name" field of the JSON object to "John Doe".

3. Setting a nested field using dot notation

This example sets a deeply nested field using dot notation.

4. Setting and modifying fields in sequence

This example shows multiple sequential modifications to JSON fields. The TermsCode is changed from "38" to 39.

5. Using set command explicitly

This example uses the explicit "set" command to modify a field.

6. Using change command

This example uses the "change" command, which is equivalent to "set".

7. Adding a new field to a JSON object

This example adds a new field "Label" to an existing JSON object. The result would be: {"TermsCode": 42, "Description": "0.5% 10 NET 45", "Label": "Default"}

8. Setting nested JSON structures

This example demonstrates setting one JSON object as a field within another JSON object.

9. Setting a list as a field value

This example shows setting a list as a field value in a JSON object.

10. Setting array element by ordinal

This example demonstrates setting array elements using ordinals like "first", "second", and "last".

11. Setting nested array fields

This example shows setting fields within objects that are elements of an array.

Last updated

Was this helpful?