INSERT_JSON$  (json$, key$, value$) (only available on Wx100 PLC firmware >= F94.2)
Purpose This provides a convenient way to append a key-value pair to an exist JSON object. (for details please refer to JSON specifications).

This function takes the json-formatted object string json$, a key string key$ and a value string value$ as parameters and returns a new JSON object string with the new key$ and value$ being appended to the last key-value pairs of the original JSON object.

If json$ is an empty string, then this function will first create an empty JSON object string "{}" and the key$ and value$ will become the first key-value pair in the newly created JSON object string and returned by this function.
Examples
A$ = ""
A$ = INSERT_JSON$(A$, "Temperature", "20.5")  ' value$ contains a primitive (number) ---(1)
B$ = INSERT_JSON$(A$, "DeviceID", "Wx100")    ' value$ contains a string literal -------(2)
C$ = INSERT_JSON$(B$, "Alarm", "False")       ' value$ contains a primitive (boolean)---(3) 
                                              ' - will convert to lower case
D$ = ""
D$ = INSERT_JSON$(D$, "Data1", C$)            ' value (C$) is a JSON object string
Comments: Result from the above statements:

(1) A$ contains: {"Temperature":20.5}
(2) B$ contains: {"Temperature":20.5,"DeviceID":"Wx100"}
(3) C$ contains: {"Temperature":20.5,"DeviceID":"Wx100","Alarm":false}
(4) D$ contains: {"Data1":{"Temperature":20.5,"DeviceID":"Wx100","Alarm":false}}

Note:
  1. INSERT_JSON$ command automatically checks the value$ type and if it finds a string representation of a number, a "true" or a "false" string (these are considered "primitives"), or a string that represents a JSON object (i.e. one that is enclosed between the '{' and '}' characters), they will not be enclosed in additional pair of double quotation characters.
  2. A non-primitive value$ is considered a string literal and INSERT_JSON$ command will add an additional pair of double quotation mark around the value$.
  3. You can observe in example (1) and (3) that adds a primitive while example (2) adds a string literal. Example (4) shows you how a JSON object (C$ in this case) can be used as a value$ to a new key-value pair where the key$ = "Data1"
  4. This function is only available on Wx100 with firmware >= F94.2. Also the maximum string length for this PLC firmware version has been increased to 232, allowing it to handle larger JSON object string.
See Also GET_JSONVAL$()

backbutton.gif (507 bytes)  Basic to TBASIC Reference Manual