JSONPUTVALUE

JSONPUTVALUE appends a value, 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; or if the specified buffer size is zero, it returns a size_t value that specifies the number of bytes that would be needed for all the JSON text to be written.

Read syntax diagramSkip visual syntax diagramJSONPUTVALUE( p, n, x,y)
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
y
An optional parameter that specifies whether names should be written in lowercase, uppercase, or asis.

y must be a character constant with one of the values LOWER, UPPER, or ASIS. These values can themselves be specified in any case. If not specified, it will default to the value in JSON(CASE) option.

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 = jsonPutValue( p, n, b );
The above code writes the following UTF-8 string to the buffer, and assigns the value 7 to the variable written.
[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 = jsonPutValue( p, n, c );
The above code writes the following UTF-8 string to the buffer, and assigns the value 13 to the variable written.
{"D":2,"E":3}