Skip to content

JSON: Set Value

Sets a value inside JSON data using a dot-separated key path. Supports navigating objects and arrays (using numeric indices for arrays) and creates intermediate objects/arrays as needed. If the key path is empty, the entire data is replaced with the provided value.
Preview

Usage

Use this node when you need to insert or update a value within nested JSON data by specifying a path like user.profile.name or items.0.title. It accepts JSON data as a dict/list or a JSON string. Typically used after parsing JSON, or before serializing back to a string, to programmatically modify specific fields.

Inputs

FieldRequiredTypeDescriptionExample
json_dataTrueWILDCARDThe JSON data to modify. Can be a dict, list, or a JSON string. If a string is provided, it will be parsed.{'user': {'name': 'Alice'}, 'items': [{'title': 'Old'}]}
key_pathTrueSTRINGDot-separated path to where the value should be set. Use numeric segments to index into arrays (e.g., items.0.title). Leave empty to replace the entire input with the provided value.items.0.title
valueTrueWILDCARDThe value to set at the specified path. Can be any JSON-serializable type.New Title

Outputs

FieldTypeDescriptionExample
updated_dataWILDCARDThe JSON data after setting the value at the specified path.{'user': {'name': 'Alice'}, 'items': [{'title': 'New Title'}]}

Important Notes

  • Path format: Use dot-separated keys; array indices must be numeric (e.g., items.2.name).
  • Empty path: If key_path is empty, the entire output becomes the provided value.
  • Input as string: If json_data is a JSON string, it is parsed; if parsing fails or results in null/empty, an empty object {} is used as the base before setting the value.
  • Intermediate creation: Missing objects/arrays are created automatically along the path. For arrays, missing indices are filled with {} for intermediate steps and None for final padding.
  • Invalid segments: Non-numeric array indices or encountering non-container types in the path will cause the operation to no-op and return the original data.
  • Return type: Output is the updated data structure (dict/list/other), not a JSON string.

Troubleshooting

  • Value not updated: Ensure array path segments are numeric (e.g., '0', '1') and that intermediate path targets are objects/arrays. Invalid segments cause the node to return the original data.
  • Output became {} or lost fields: If you passed an invalid JSON string as input, parsing fails and the node starts from an empty object. Validate the JSON first using a JSON validation node or ensure the input string is valid.
  • Setting inside arrays behaves unexpectedly: When extending arrays to reach an index, intermediate elements are created. For intermediate steps they are {}, and for final padding they are None; verify your path and expected structure.
  • Whole data replaced: This happens when key_path is empty; provide a proper path if you intend to modify only a part of the data.