This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v20.6
JSON PARSE ARRAY
|
JSON PARSE ARRAY ( jsonString ; array ) | ||||||||
Parameter | Type | Description | ||||||
jsonString | String |
![]() |
JSON string to parse | |||||
array | Array |
![]() |
Array containing result from parsing of JSON string | |||||
The JSON PARSE ARRAY command parses the contents of a JSON-formatted string and puts the data extracted into the array parameter. This command deserializes the JSON data; it performs the opposite action of the JSON Stringify array command.
In jsonString, pass the JSON-formatted string whose contents you want to parse. This string must be formatted correctly, otherwise a parsing error is generated.
In array, pass an array of the desired type to receive the parsing results.
Note: Starting with 4D v16 R4, JSON PARSE ARRAY can usually be replaced by a call to JSON Parse that returns a collection. Collections are based on JSON arrays and allow to store data of mixed types, which provides more flexibility than arrays.
In this example, data from fields of the records in a table are extracted and then placed in object arrays:
C_OBJECT($ref)
ARRAY OBJECT($sel;0)
ARRAY OBJECT($sel2;0)
C_TEXT(v_String)
OB SET($ref;"name";->[Company]Company Name)
OB SET($ref;"city";->[Company]City)
While(Not(End selection([Company])))
$ref_company:=OB Copy($ref;True)
APPEND TO ARRAY($sel;$ref_company)
// $sel{1}={"name":"4D SAS","city":"Clichy"}
// $sel{2}={"name":"MyComp","city":"Lyon"}
// ...
NEXT RECORD([Company])
End while
v_String:=JSON Stringify array($sel)
// v_String= [{"name":"4D SAS","city":"Clichy"},{"name":"MyComp","city":"Lyon"}...]
JSON PARSE ARRAY(v_String;$sel2)
// $sel2{1}={"name":"4D SAS","city":"Clichy"}
// $sel2{2}={"name":"MyComp","city":"Lyon"}
//...
Product: 4D
Theme: JSON
Number:
1219
Created: 4D v14
Modified: 4D v16 R4
4D Language Reference ( 4D v20)
4D Language Reference ( 4D v20.1)
4D Language Reference ( 4D v20.2)
4D Language Reference ( 4D v20.3)
4D Language Reference ( 4D v20.4)
4D Language Reference ( 4D v20.5)
4D Language Reference ( 4D v20.6)