The DATA-INTO operation imports the data from a structured document into an RPG variable.
The DATA-INTO operation passes the document text to the parser, which uses callback functions to gradually pass the names and values of the data in the document to the DATA-INTO operation. The DATA-INTO operation places the information into the target RPG variable.
Options can be set to instruct the DATA-INTO operation and the parser how the parsing should be handled.
Options:
- doc=file
– Indicates the the text document should be read from the IFS. The path and the filename is place in the variable of the first %data parameter. - case=any (default is yes)
– Indicates that the mapping of the name of the document is case insensitive. - trim=none (default is all)
– Indicates if leading and trailing blank characters should be trimmed or not when moved into matching variable. - allowmissing=yes (default is no)
– Indicates that names/keys in the text document can be less than in the receiving RPG variable/datastructure. - allowextra=yes (default is no)
– Indicates that names/keys in the text document can be more than in the receiving RPG variable/datastructure. - countprefix=count_
– Defines how count variables can be named in the datastructure for multiple dimensioned structures. The number of loaded elements will be stored in the count varable after the completed parsing.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// Declare the receiving datastructure that maps the JSON document data dcl-ds PersonsDS qualified; count_Persons int(5); dcl-ds Persons dim(999); FirstName varchar(128); LastName varchar(128); end-ds; end-ds; // Declare the variable for the variable the should hold the JSON document data dcl-s jsonData varchar(1024); // Construct the JSON document data jsonData = '{"Persons" : [ {"FirstName" : "John", "LastName" : "Smith"}, {"FirstName" : "Lisa", "LastName" : "Jackson"} ]}'; // Parse the JSON document data into the datastructure data-into PersonsDS %data(jsonData : 'case=any trim=none allowmissing=yes allowextra=yes countprefix=count_') %parser('YAJL/YAJLINTO'); |