4D v14.3

JSON TO SELECTION

Home

 
4D v14.3
JSON TO SELECTION

JSON TO SELECTION 


 

JSON TO SELECTION ( aTable ; jsonObject ) 
Parameter Type   Description
aTable  Pointer in Pointer to 4D table
jsonObject  Text in String in JSON

The JSON TO SELECTION command copies the contents of a JSON object to the selection of records of aTable.

If a selection exists for aTable at the time of the call, the elements of the JSON object are copied into the records based on the order of the object and the order of the records. If the number of elements defined in the JSON object is greater than the number of records in the current selection, new records are created. The records, whether they are new or existing, are automatically saved.

Warning: Since JSON TO SELECTION replaces any information found in the existing records, this command must be used with caution.

If a record is locked by another process during the execution of the command, it is not modified. All the locked records are placed in the The LockedSet System Set. After the execution of JSON TO SELECTION, you can test whether the LockedSet set contains any records that were locked.

Example  

Using the JSON TO SELECTION command to add records to the [Company] table:

 C_OBJECT($Object1;$Object2;$Object3;$Object4)
 C_TEXT($ObjectString)
 ARRAY OBJECT($arrayObject;0)
 
 OB SET($Object1;"ID";"200";"Company Name";"4D SAS";"City";"Clichy")
 APPEND TO ARRAY($arrayObject;$Object1)
 
 OB SET($Object2;"ID";"201";"Company Name";"APPLE";"City";"Paris")
 APPEND TO ARRAY($arrayObject;$Object2)
 
 OB SET($Object3;"ID";"202";"Company Name";"IBM";"City";"London")
 APPEND TO ARRAY($arrayObject;$Object3)
 
 OB SET($Object4;"ID";"203";"Company Name";"MICROSOFT";"City";"New York")
 APPEND TO ARRAY($arrayObject;$Object4)
 
 $ObjectString:=JSON Stringify array($arrayObject)
 
  // $ObjectString = "[{"ID":"200","City":"Clichy","Company Name":"4D
  // SAS"},{"ID":"201","City":"Paris","Company Name":"APPLE"},{"ID":"202",
  //"City":"London","Company Name":"IBM"},{"ID":"203","City":"New
  //York","Company Name":"MICROSOFT"}]"
 
 JSON TO SELECTION([Company];$ObjectString)
  // You create 4 records in the [Company] table, filling the ID,
  //Company name and city fields

 
PROPERTIES 

Product: 4D
Theme: JSON
Number: 1235

 
HISTORY 

New
Created: 4D v14

 
SEE ALSO 

Selection to JSON

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)