4D v14.3Selection to JSON |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
Selection to JSON
|
Selection to JSON ( aTable {; aField}{; aField2 ; ... ; aFieldN}{; template}) -> Function result | ||||||||
Parameter | Type | Description | ||||||
aTable | Table |
![]() |
Table to serialize | |||||
aField | Field |
![]() |
Field(s) whose contents must be serialized | |||||
template | Object |
![]() |
Object for selection of labels and fields | |||||
Function result | Text |
![]() |
String containing serialized JSON array | |||||
The Selection to JSON command returns a JSON string containing the values of the fields for the current selection of aTable.
If you only pass the aTable parameter, the command includes, in the JSON string, the values of all the fields of the table that can be expressed in JSON. BLOB and Picture type fields are ignored.
If you do not want to include all the fields of aTable, you can use either the aField parameter or the template parameter:
You want to create a JSON string representing this selection:
1) You want to include the values of all the fields of the [Members] table:
$jsonString :=Selection to JSON([Members])
// $jsonString =[{"LastName":"Durant","FirstName":"Mark","Address":
//"25 Park St","Zip code":"15205","City":"Pittsburgh"},{"LastName":
//"Smith","FirstName":"John","Address":"24 Philadelphia Ave","Zip code":
//"75203","City":"Dallas"},{"LastName":"Anderson","FirstName"
//:"Adeline","Address":"37 Market St","Zip code":"45205","City":"Cincinnati"},...]
2) You want to reduce the selection and only include two fields in the JSON string by using the syntax based on fields:
QUERY([Members];[Members]LastName="A@")
$jsonString :=Selection to JSON([Members];[Members]LastName;[Members]City)
// $jsonString = [{"LastName":"Anderson","City":"Cincinnati"},{"LastName":"Albert","City":"Houston"}]
3) You only want to include one field in the JSON string by using the template syntax:
C_OBJECT($template)
OB SET($template;"LastName";->[Members]LastName) // a single field
ALL RECORDS([Members])
$jsonString :=Selection to JSON([Members];$template)
// $jsonString = [{"LastName":"Durant"},{"LastName":"Smith"},{"LastName":"Anderson"},
// {"LastName":"Albert"},{"LastName":"Leonard"},{"LastName":"Pradel"}]
Product: 4D
Theme: JSON
Number:
1234
Created: 4D v14
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)