Append items to a JSON array
Add new values to an array in your original JSON. You can add text, numbers, true or false values, objects, other arrays, or null.
Application
- JSON
Inputs (what you have)
| Name | Description | Data Type | Required? | Example |
|---|---|---|---|---|
| Original JSON | The JSON you want to update. | Text (Long) | Yes | {"items": ["value1", "value2"]} |
| New items | The content you want to add, written as JSON. This can be any JSON value, such as text, a number, an object or an array. | Text (Long) | Yes | {"name": "Blue"} |
| JSON path location of array | Where to add the new content. The path must point to an existing array in Original JSON. Use $ if Original JSON is itself an array. | Text (Short) | Yes | $.items |
| Remove quotes? | Choose whether text such as "3" becomes a number. Off by default. See the comparison below. | True/False | No | false |
What to enter in New items
New items accepts any JSON value. A single value is added as one item. If you provide an array, each value in that array is added separately. Text needs double quotes, for example "Blue".
| What you want to add | Enter in New items | What gets added |
|---|---|---|
| One text item | "Blue" | The text Blue |
| Several text items | ["Blue", "Green"] | Two separate text items |
| A number | 3 | The number 3 |
| A true or false value | false | A false value |
| An empty value | null | An empty value |
| An object | {"name": "Blue"} | One object containing name and its value |
| An array as one item | [[1, 2]] | One item containing the array [1, 2] |
For example, you can add an object to an array within a larger JSON document:
| Input | Value |
|---|---|
| Original JSON | {"order_id": 123, "items": [{"name": "Blue"}]} |
| New items | {"name": "Green"} |
| JSON path location of array | $.items |
The result keeps the rest of the original JSON and adds the new object to items:
{"order_id": 123, "items": [{"name": "Blue"}, {"name": "Green"}]}
Quotes, line breaks and backslashes in text
Use \" for a quote inside text, \n for a line break and \\ for a backslash. This example adds one text item containing all three:
"say \"hello\"\nC:\\temp"
Remove quotes?
Leave Remove quotes? off (false) when you want text to stay text. Turn it on (true) when text such as "3" should become a number.
| Enter in New items | Off: false (default) | On: true |
|---|---|---|
["3", "true", "null"] | Keeps all three as text: ["3", "true", "null"] | Changes them to a number, a true value and an empty value: [3, true, null] |
["-3", "1.5", "Blue"] | Keeps all three as text | Keeps all three as text |
[0, false, null, {"name": "Blue"}] | Keeps the number, false value, empty value and record | Keeps the same values |
When on, this option also recognizes "True", "False" and "None", and can turn text containing a JSON object or array into that object or array.
New items must be valid JSON with either setting. Turning this option on does not allow text without the surrounding double quotes.
Outputs (what you get)
| Name | Description | Data Type | Required? | Example |
|---|---|---|---|---|
| Appended JSON | The updated JSON with the new content added at the selected array. | Text (Long) | No | {"order_id": 123, "items": [{"name": "Blue"}, {"name": "Green"}]} |
Outcomes
| Name | Description |
|---|---|
| Success | The new content was added to the selected array. |
Requirements
- N/A