JSONGetElementType

Validates and returns the JSON data type for an element specified by an object name, an array index, or a path.

Format 

JSONGetElementType ( json ; keyOrIndexOrPath )

Parameters 

json - any text expression or field that contains a JSON object or array.

keyOrIndexOrPath - any text expression or field that specifies a JSON object name (key), an array index, or a path. See Working with the JSON functions.

Data type returned 

text, number

Originated in version 

19.5.1

Description 

If the JSON value at keyOrIndexOrPath is valid, this function returns the data type of that value returned as a number; otherwise, it returns an error text message. The data type numbers also have named values of JSONString, JSONNumber, JSONObject, JSONArray, JSONBoolean, and JSONNull. The JSONRaw data type value will never be returned. See JSONSetElement for more information about these data types.

Example 1 

Validates that the text is a valid JSON object.

(JSONGetElementType( "{ \"a\" : 11 }"; "" ) = JSONObject) returns 1 (true) as a number.

(JSONGetElementType( "{ a : 11 }"; "" ) = JSONObject) returns 0 (false) as a number.

Example 2 

Returns the type of a specific JSON element.

JSONGetElementType( "{ \"a\" : 11 , \"b\" : false }"; "b" ) returns 5 (JSONBoolean) as a number.

Example 3 

Checks JSON data for an element type that is invalid.

JSONGetElementType( "[100, 200]"; "3" ) returns "? Incorrect key, index, or path" as a string.