Skip to main content
Version: 7.9

jsonSet

New in 7.9.2

This function is used by Ignition's Expression language.

Description

Takes a JSON friendly string, a path string, and value, and will return a new JSON friendly string with the provided path set to the provided value. This is best used in conjunction with the Derived Tags writeback value.

Syntax

jsonSet(json, path, value)

  • Parameters

    • string json - The JSON string. The string must be in a JSON friendly format.

      //The json parameter must be wrapped in {}, and contain a colon between the key and the value.
      //Since the parameter passed is a string datatype, the whole parameter must be wrapped in quotes.
      "{key:value}"

      //You may optionally wrap strings in quotation marks.
      "{'key':'value'}"

      //You may also nest objects inside of the value, much like you can do with Python dictionaries.
      "{keyCollection1:{firstKey:value1, secondKey:value2}, keyCollection2:{firstKey:value1, secondKey:value2}}"
    • string path - The path string.

    • object value - The replacement for the value at the path.

  • Results

    • string - A JSON friendly string with a new value set at the specified path.

Examples

Code Snippet
// This example takes a JSON friendly string and sets the provided path to the given value. This would then return the string {'item':{'firstThing':1, 'secondThing':5}}

jsonSet("{'item':{'firstThing':1, 'secondThing':2}}", "item.secondThing", 5)