The JSON.parse() method parses a JSON string, constructing the P# value or object described by the string. Used in integrating data into signals by extracting string values.
Syntax
ParseJSON("Signal Istring)" in "", "Data Key/column name")
Parameters
- Signal: Can be any distinguishing signal that has String Json values.
The below example shows the signal “Expenses Json” populated by Json script.
- Data Key: The Key refers the first Value in the Json format. In cases of multiple values, the key value can also be used for cumulative values.
Return value
- Array, string, number, boolean, or null value corresponding to the given JSON text.
- However, these values need to be set to numerical values when assigning to time numerical signals.
- The result needs to be a single values being saved into the signal to prevent syntax error or type error.
Exceptions
Throws a SyntaxError exception if the string to parse is not valid JSON.
Example
Table "Expenses"
Column "Static Numeric" in "USD" saving "Number of Roads"
ParseJSON("expenses Json" in " ", "R&M - Roads")
End column
End Table
Result : Sting values populate the signal
Example
ParseJSON(“Signal (string)” in “ “, "Data Key/column name")
Table "LOE Summary"
Column "gross operating expenditure" in "USD" saving "gross operating expenditure"
Todouble(ParseJSON("expenses Json", "Pumper/Gauger")) !+
Todouble(ParseJSON("expenses Json" in " ", "R&M - Roads")) !+
Todouble(ParseJSON("expenses Json" in " ", "R&M - Well Location")) !+
Todouble(ParseJSON("expenses Json" in " ", "R&M - Battery Location")) !+
Todouble(ParseJSON("expenses Json" in " ", "R&M - Pumping Unit")) !+
Todouble(ParseJSON("expenses Json" in " ", "R&M - Wellhead Equip"))
End Column
End Table
Result: Each instance of Parse Json is converted to a “Double” type and added to populate the "gross operating expenditure" signal.
- ToDouble()
- ToInteger()
Example
Data format : {“R&M – Roads : “42, 56, 76”}
Table "Expenses"
Column "Static Numeric" in "USD" saving "Number of Roads"
Sum(Todouble(ParseJSON("expenses Json" in " ", "R&M - Roads")))
End column
End Table
Result : Cumulated Numeric values will be added to the signal “Number of Roads”.