Skip to content

Object Json

Name Input Params Return Data Description
json_getfield String, String String, String Get the value of the selected Json Field

json_getfield(String, String)

Get the value of the selected Json Field.
This function can elaborate well-structured json, with multiple subfields and arrays.
To access the values of a sub array, the field must be "Field.SubField", in this way the function will take all the values within the first index of the sub array.
Subsequently, to take the values of sub arrays of sub arrays, the Field has to be "Field.Index.SubField", "Field.SubField.Index" and so on.

Example
Value, err = json_getfield(Json, Field)
Input Parameters
 - Json (String): The Json that contains the values.
 - Field (String): The interested field in the Json.
Returns
 - Value (String): The function returns the Value of the selected Field in the Json.
 - err (String): The function returns the error if is it present.

Json = '{"name":"John", "age":30, "cars": [{"Bmw":"M4", "Audi":"A3", "Volkswagen":"Golf"}, {"Lamborghini":"Murcielago", "Ferrari":"F40", "Pagani":"Huayra"}, {"Suzuki":"Vitara", "Nissan":"GTR R33", "Subaru":"Impreza WRX"}]}'
                -- The Json that contains the values
Field = "cars"  -- The interested field in the Json
Value, err = json_getfield(Json, Field)
resiot_debug(Value)
--  
-- Result Example:
--  
-- Value = "[{"Audi":"A3","Bmw":"M4","Volkswagen":"Golf"},{"Ferrari":"F40","Lamborghini":"Murcielago","Pagani":"Huayra"},{"Nissan":"GTR R33","Subaru":"Impreza WRX","Suzuki":"Vitara"}]"
-- 
Field = "cars.1"    -- The interested field in the Json
Value, err = json_getfield(Json, Field)
resiot_debug(Value)
-- 
-- Result Example:
-- 
-- Value = "{"Ferrari":"F40","Lamborghini":"Murcielago","Pagani":"Huayra"}"
-- 
-- err = ""
-- 
Field = "cars.1.Ferrari"    -- The interested field in the Json
Value = json_getfield(Json, Field)
resiot_debug(Value)
-- 
-- Result Example:
-- 
-- Value = "F40"
-- 
-- err = ""
-- 
Field = "cars.2.Toyota"     -- The interested field in the Json
Value = json_getfield(Json, Field)
resiot_debug(Value)
-- 
-- Result Example:
-- Value = ""
-- 
-- err = ""
-- 

Return to index