util.JSONObject.getKey()

util.JSONObject.getKey() returns the key of the key:value pair by its index.

Syntax

CALL util.JSONObject.getKey(pair_index)

Parameters

pair_index

an index of the element of the JSON object (= the key:value pair)

Usage and examples

util.JSONObject.key() takes the pair index in the JSON object as the parameter and returns the key.

The index of the first key:value pair is 1.

If the JSON object included no pair with the specified name, the method returns NULL.

MAIN
DEFINE json_obj util.JSONObject
LET json_obj=util.JSONObject.parse('{"id":123, "name":"Scott", "surname":"Smith"}')
DISPLAY json_obj.getKey(1)
DISPLAY json_obj.getKey(2)
DISPLAY json_obj.getKey(3)
CALL fgl_getkey()
END MAIN

This method can be used together with util.JSONObject.getLength() and util.JSONObject.getType() in order to read the elements of JSON objects:

MAIN
DEFINE json_obj util.JSONObject
DEFINE i INTEGER
LET json_obj=util.JSONObject.parse('{"id":12, "name":"Scott, Frank", "address":"5 Brando Str."}')
FOR i=1 TO json_obj.getLength()
  DISPLAY i,": ",json_obj.name(i),"=",json_obj.get(json_obj.name(i))
END FOR
CALL fgl_getkey()
END MAIN

 

 

Contact Us

Privacy Policy

Copyright © 2025 Querix, (UK) Ltd.