jsonFormat
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 respect 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; see examples below for possibilities.
Results
- string - A prettyprint string of the specified string.
Examples​
Code Snippet
// This example builds a JSON friendly string, and returns a prettyprint version of the string.
// Since the parameter passed is a string data type, the whole parameter must be wrapped in quotes.
jsonFormat("{item1:10,item2:20}")
Code Snippet
// Another valid JSON format - you may optionally wrap inner strings in quotation marks.
jsonFormat("[{'item1':'apples','item2':'bananas'},{'item1':'oranges','item2':'carrots'}]")