Xbasic
json_extract Function
Syntax
C text = json_extract(json_text as C, property_name as C)
Arguments
- json_textCharacter
A string that contains the JSON object to search.
- property_nameCharacter
The name of the property to find and extract from the JSON object.
Description
Extracts a property from a JSON object.
Discussion
The JSON text passed to the function must be properly formed (i.e. use double quotes on property and string names). You can use json_reformat_safe() to 'clean' up the JSON string before calling json_extract.
Example
dim json as c json = <<%txt% { name: 'Fred', address: { street: '123 Main St', city: 'Boston', state: 'MA' } } %txt% 'json_extract() requires properly formed JSON, so 'we first call json_reformat_safe() dim json2 as c json2 = json_reformat_safe(json) ?json_extract(json2,"name") = "Fred" ?json_extract(json2,"address") = { "street": "123 Main St", "city": "Boston", "state": "MA" }
See Also