JSON functions work on data that is of type string.

isValidJSON

isValidJSON determines if a string is a valid JSON object.

Parameters:

  • the_string - the string that may or may not be JSON.

Usage:

  • `isValidJSON(the_string)

Returns:

  • 0 if the_string is not valid JSON
  • 1 if the_string is valid JSON

JSONExtract

The JSONExtract<Type> methods return the value of the_key depending on the type specified. the_key cannot be nested. Can be called specifically like JSONExtractString or more generalized like JSONExtract(..,..,'String')

Accepts: ArrayRaw, Bool, Float, Int, String, Raw, UInt,
Parameters:

  • the_JSON - the string representation of the JSON to analyze.
  • the_key - the key to search for in the document
  • the_type - if using the more generalized JSONExtract

Usage:

  • JSONExtract<Type>(the_JSON, the_key)
  • JSONExtract(the_json, the_key, the_type)

Returns:

  • The value of the_key as the type specified.

jsonExtractKeysAndValues

JSONExtractKeysAndValues extracts an array of tuples from a JSON document, where all of the values are of a given type. For example, all String keys and values can be extracted from a document at once as an array of tuples.

Parameters:

  • the_JSON - the string representation of the JSON to analyze.
  • the_top_level_key - the key to search for in the document
  • the_type - if using the more generalized JSONExtract

Usage:

  • JSONExtractKeysAndValues(the_json, the_key, the_type)

Returns:

  • An array of (key, value) tuples, where all tuple's values are of type the_type

JSONHas

JSONHas checks to see if the JSON document contains a specified key at the top level of the document.

Parameters:

  • the_JSON - the string representation of the JSON to analyze.
  • the_key - the key to search for in the document

Usage:

  • `JSONHas(the_JSON, the_key)

Returns:

  • 0 if the_key is not in the_JSON
  • 1 if the_key is in the_JSON

JSONLength

JSONLength returns the number of keys in a JSON value, or, if the JSON is an array, the length of the array.

Parameters:

  • the_JSON - the string representation of the JSON to analyze.
  • the_key - the key to search for in the document

Usage:

  • `JSONLength(the_JSON, the_key)

Returns:

  • uint representing the length of the JSON value. If the_key does not exist, returns 0

JSONType

JSONType returns the the JSON type of the value of the_key. Only works on the current top level keys. If the type of a nested key is needed, combine with visitParamExtractRaw to get the nested JSON document.

Parameters:

  • the_JSON - the string representation of the JSON to analyze.
  • the_key - the key to search for in the document

Usage:

  • `JSONType(the_JSON, the_key)

Returns:

  • string representing the type of the_key
  • if the_key does not exist, returns Null

visitParamExtractRaw

visitParamExtractRaw returns the value of the the_key if it exists at any nesting level in the document.

Parameters:

  • the_JSON - the string representation of the JSON to analyze.
  • the_key - the key to search for in the document

Usage:

  • `visitParamExtractRaw(the_JSON, the_key)

Returns:

  • a string representing the value of the_key
  • if the_key does not exist, returns ''
  • if the_JSON is not well formed, returns ''

visitParamHas

visitParamHas checks to see if the JSON document contains a specified key.

Parameters:

  • the_JSON - the string representation of the JSON to analyze.
  • the_key - the key to search for in the document

Usage:

  • `visitParamHas(the_JSON, the_key)

Returns:

  • 0 if the_key is not in the_JSON
  • 1 if the_key is in the_JSON

Did this page help you?