4D v17.4JSON Stringify array | 
            ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
                 
                
    
    
                 | 
                
			
                    
                         
    4D v17.4
 
JSON Stringify array 
                                
                                
        
 | 
                |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JSON Stringify array ( array {; *} ) -> Function result | ||||||||
| Parameter | Type | Description | ||||||
| array | Text array, Real array, Boolean array, Pointer array, Object array | 
             
         | 
        Array whose contents must be serialized | |||||
| * | Operator | 
             
         | 
        Pretty formatting | |||||
| Function result | Text | 
             
         | 
        String containing the serialized JSON array | |||||
The JSON Stringify array command converts the 4D array array into a serialized JSON array. This command performs the opposite action of the JSON PARSE ARRAY command.
In array, pass a 4D array containing the data to be serialized. This array may be of the text, real, Boolean, pointer or object type.
Note: If you pass a scalar variable or field in array, the command will return a string with the parameter value between "[ ]".
You can pass the optional * parameter to use pretty formatting in the resulting string. This improves the presentation of JSON data by including formatting characters when it is displayed in a Web page.
Conversion of a text array:
 C_TEXT($jsonString)
 ARRAY TEXT($ArrayFirstname;2)
 $ArrayFirstname{1}:="John"
 $ArrayFirstname{2}:="Jim"
 $jsonString :=JSON Stringify array($ArrayFirstname)
 
  // $jsonString = "["John","Jim"]"Conversion of a text array containing numbers:
 ARRAY TEXT($phoneNumbers;0)
 APPEND TO ARRAY($phoneNumbers ;"555-0100")
 APPEND TO ARRAY($phoneNumbers ;"555-0120")
 $string :=JSON Stringify array($phoneNumbers)
  // $string = "["555-0100","555-0120"]"Conversion of an object array:
 C_OBJECT($ref_john)
 C_OBJECT($ref_jim)
 ARRAY OBJECT($myArray;0)
 OB SET($ref_john;"name";"John";"age";35)
 OB SET($ref_jim;"name";"Jim";"age";40)
 APPEND TO ARRAY($myArray ;$ref_john)
 APPEND TO ARRAY($myArray ;$ref_jim)
 $JsonString :=JSON Stringify array($myArray)
  // $JsonString = "[{"name":"John","age":35},{"name":"Jim","age":40}]"
 
  // If you want to view the result in a Web page,
  // pass the optional * parameter:
 $JsonStringPretty :=JSON Stringify array($myArray;*)
Conversion of a 4D selection in an object array:
 C_OBJECT($jsonObject)
 C_TEXT($jsonString)
 
 QUERY([Company];[Company]Company Name="a@")
 OB SET($jsonObject;"company name";->[Company]Company Name)
 OB SET($jsonObject;"city";->[Company]City)
 OB SET($jsonObject;"date";[Company]Date_input)
 OB SET($jsonObject;"time";[Company]Time_input)
 ARRAY OBJECT($arraySel;0)
 
 While(Not(End selection([Company])))
    $ref_value:=OB Copy($jsonObject;True)
  // If you do not copy them, the values will be empty strings
    APPEND TO ARRAY($arraySel;$ref_value)
  // Each element contains the selected values, for example:
  // $arraySel{1} = // {"company name":"APPLE","time":43200000,"city":
  // "Paris","date":"2012-08-02T00:00:00Z"}
    NEXT RECORD([Company])
 End while
 
 $jsonString:=JSON Stringify array($arraySel)
  // $jsonString = "[{"company name":"APPLE","time":43200000,"city":
  //"Paris","date":"2012-08-02T00:00:00Z"},{"company name":
  //"ALMANZA",...}]"
	Product:  4D
	Theme:  JSON
	Number:  
        1228
        
        
        
	
	Created:  4D v14
	
	
	
	4D Language Reference ( 4D v17)
	
	
	
	
	4D Language Reference ( 4D v17.1)
	
	4D Language Reference ( 4D v17.2)
	
	4D Language Reference ( 4D v17.3)
	
	4D Language Reference ( 4D v17.4)
	
	
Add a comment