JSONPUTMEMBER

JSONPUTMEMBER appends a member (or name-value pair), as UTF-8, to the JSON text. This function returns a size_t 1 value that specifies the number of bytes that are written to the buffer.

Read syntax diagramSkip visual syntax diagram
>>-JSONPUTMEMBER(p,n,x)----------------------------------------><

p
A pointer that specifies the address of a buffer to be written.
n
A size_t that specifies the number of available bytes in the buffer.
x
A variable reference whose value is to be written to the buffer. The variable reference must not contain any of these elements:
  • UNIONs
  • Noncomputational elements
  • GRAPHIC elements
  • COMPLEX elements
  • FIXED(p,q) elements with q < 0 or q > p
  • Unnamed elements

Example 1

  dcl b(3)    fixed bin init(2,3,5);
  dcl buffer  char(1000);
  dcl p       pointer;
  dcl n       fixed bin(31);

  p = addr(buffer);
  n = length(buffer);
  written = jsonPutMember( p, n, b );

The above code writes the following UTF-8 string to the buffer, and assigns the value 11 to the variable written.

"B":[2,3,5]

Example 2

  dcl 1 c, 2 d fixed bin init(2), 2 e fixed bin init(3);
  dcl buffer  char(1000);
  dcl p       pointer;
  dcl n       fixed bin(31);

  p = addr(buffer);
  n = length(buffer);
  written = jsonPutMember( p, n, c );
The above code writes the following UTF-8 string to the buffer, and assigns the value 17 to the variable written.
"C":{"D":2,"E":3}

Example 3

  dcl 1 c(2), 2 d fixed bin init(2,3), 2 d fixed bin init(5,7);
  dcl buffer  char(1000);
  dcl p       pointer;
  dcl n       fixed bin(31);

  p = addr(buffer);
  n = length(buffer);
  written = jsonPutMember( p, n, c );
The above code writes the following UTF-8 string to the buffer, and assigns the value 33 to the variable written.
"C":[{"D":2,"E":5},{"D":3,"E":7}]

Example 4

  dcl x       fixed bin(31) init(11);
  dcl y       fixed bin(31) init(13);
  dcl buffer  char(1000);
  dcl p       pointer;
  dcl n       fixed bin(31);

  p = addr(buffer);
  n = length(buffer);
  written = 0;
  written += jsonPutObjectStart( p+written, n-written );
  written += jsonPutMember( p+written, n-written, x );
  written += jsonPutComma( p+written, n-written );
  written += jsonPutMember( p+written, n-written, y );
  written += jsonPutObjectEnd( p+written, n-written );
The above code writes the following UTF-8 string to the buffer, and assigns the value 15 to the variable written.
{"X":11,"Y":13}

Unlike the previous examples, this buffer contains complete, valid JSON text.