Server Reference Guide : 11. JSON-RPC 2.0 Interface : Returning Values to the Caller : Using a JsonValue as a Return Value
 
Share this page                  
Using a JsonValue as a Return Value
You can define the Return Type of the 4GL procedure as JsonValue. Then you can construct the result by creating an object of a JsonValue subclass, populating its value and returning this object.
Example of procedure myproc defined as returning a JsonValue
PROCEDURE myproc(x=integer not null)=
DECLARE
  y = varchar(10) not null;
  retval = JsonObject; 
ENDDECLARE
{
  y = 'hello';
  x = x*100;
  // Now construct the result
  retval.NewMember(name = 'x_new', value = x);
  retval.NewMember(name = 'y', value = y);
  // result will contain members "x_new" and "y"
  RETURN retval;
}