Skip to main content
Version: 7.9

jsonFormat

New in 7.9.2

This function is used by Ignition's Expression language.

Description

Takes a string, and returns a prettyprints string: making the string easier to read by humans. Especially useful in cases where the string is displayed on components that can demonstrate carriage returns.

The image below shows a Label component with a JSON-friendly string. Below that are two Text Area components that are bound to the Label's text: one using the jsonFormat() function and the other without.

Syntax

jsonFormat(string)

  • Parameters

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

      //The string 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}}"
  • Results

    • string - A prettyprints string of the specified string.

Examples

Code Snippet
// This example builds a JSON friendly string, and returns a prettyprint version of the string.
// Useful with Text Area components.
jsonFormat("{item:{firstThing:1, secondThing:2}}")