JSON

json_Encode()

Serialize an xDev value as UTF-8 JSON

Syntax

Signature
json_Encode( xValue, [lPretty] ) --> cJson | NIL

Arguments

xValue

Value to serialize.

lPretty

Pass .T. for indented output. The default is compact output.

Return value

JSON text, or NIL when encoding fails. Read json_Error() for the reason.

Description

A hash becomes a JSON object and an array becomes a JSON array. A nonempty date becomes a string in YYYY-MM-DD form. Empty dates, NIL, xDev objects, code blocks and pointers become JSON null. Cyclic containers and excessive nesting cause encoding to fail.

Example

json_Encode.prg
PROCEDURE Main()

   LOCAL hData := { "name" => "Ada", "items" => { 1, .T., NIL } }

   QOut( json_Encode( hData ) )
   QOut( json_Encode( hData, .T. ) )

RETURN

See also