JSONGETMEMBER reads a member (a name-value pair) from the JSON text buffer and returns the number of bytes read. A JSON member is of the following form:
"Name" : value (name in double quotes, followed by a colon, followed its value). Where:
Examples of name-value pairs include:
"Details" : [ { "No": 1, "Name": "Accident","Place": "Maryland", "Really":true}, { "No": 2, "Name": "Boring", "Place": "Oregon", "Really": true}, { "No": 3, "Name": "Dull", "Place": "Scotland","Really": true}, { "No": 4, "Name": "Noplace", "Place": "England","Really": false}, { "No": 5, "Name": "Why", "Place": "Arizona", "Really": true}, { "No": 6, "Name": "Zzyzx", "Place":"California","Really":true} ]
The ERROR condition is raised if the JSON text is invalid (for example, member name does not match or the value is invalid, etc.). The ONCODE built-in function tells you why the ERROR condition was raised and the ONSUBCODE built-in function will give you the position of the invalid character, which you can use to examine the invalid character and/or replace it with a valid character.
If the third argument is omitted, the data read is effectively thrown away. If the third argument is present, the data is assigned (after appropriate conversions) to the PL/I variable(s). If the variable has the CHARACTER type, it is converted from UTF-8 to character before assignment.
For a complete program using various JSON built-in functions, see the last example under JSONPUTVALUE.
Example 1:
Dcl Array(5) fixed bin(31);
Example 2:
Dcl Towns fixed bin(31);
Example 3:
Suppose the buffer (pointed to by bufp) contains
"S3": {"FD":[ {"D2": 2, "D5": 5}, {"D2": 4, "D5": 9}]}, then bytes = jsongetmember(bufp, bufl s3); will assign data to the structure S3.
dcl 1 S3, 2 fd(2), 3 d2 fixed bin(15), 3 d5 fixed dec(7);