Functions

json.q File Reference

defines the functions exported by the module More...

Functions

string makeJSONString (any $data,*string $encoding)
 Serializes qore data into a JSON string, without any line breaks.
string makeFormattedJSONString (any $data,*string $encoding)
 Serializes qore data into a JSON string, formatted with line breaks for easier readability.
any parseJSON (string $json_string)
 Parses a JSON string and returns the corresponding Qore data structure.
nothing parseJSON ()
 This is a variant that is basically a noop, included for backwards-compatibility for functions that ignored type errors in the calling parameters.
string makeJSONRPCRequestString (string $method_name, any $version, any $id, any $request_msg)
 Creates a JSON-RPC request string from the parameters passed, without any line breaks.
string makeFormattedJSONRPCRequestString (string $method_name, any $version, any $id, any $request_msg)
 Creates a JSON-RPC request string from the parameters passed, formatted with line breaks for easier readability.
string makeJSONRPCResponseString (any $version, any $id, any $response_msg)
 Creates a JSON-RPC response string from the parameters passed, without any line breaks.
string makeFormattedJSONRPCResponseString (any $version, any $id, any $response_msg)
 Creates a JSON-RPC response string from the parameters passed, formatted with line breaks for easier readability.
string makeJSONRPCErrorString (any $version, any $id, any $error_msg)
 Creates a generic JSON-RPC error response string from the parameters passed, without any line breaks.
string makeFormattedJSONRPCErrorString (any $version, any $id, any $error_msg)
 Creates a generic JSON-RPC error response string from the parameters passed, formatted with line breaks for easier readability.
string makeJSONRPC11ErrorString (softint $code, string $error, any $id, any $error_msg)
 Creates a JSON-RPC 1.1 error response string from the parameters passed, without any line breaks.
string makeFormattedJSONRPC11ErrorString (softint $code, string $error, any $id, any $error_msg)
 Creates a JSON-RPC 1.1 error response string from the parameters passed, formatted with line breaks for easier readability.

Detailed Description

defines the functions exported by the module


Function Documentation

string makeFormattedJSONRPC11ErrorString ( softint  $code,
string  $error,
any  $id,
any  $error_msg 
)

Creates a JSON-RPC 1.1 error response string from the parameters passed, formatted with line breaks for easier readability.

Parameters:
$codethe error code to return
$errora string error message
$idthe ID of the call
$error_msgthe parameters for the error response message/message payload
Returns:
a JSON string representing the JSON-RPC 1.1 error response, formatted with line breaks for easier readability
Exceptions:
MAKE-JSONRPC11-ERROR-STRING-ERRORthe error code is not between 100-999 or empty error message string
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeFormattedJSONRPC11ErrorString(200, $msg, $id, $error); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
JSON-RPC
string makeFormattedJSONRPCErrorString ( any  $version,
any  $id,
any  $error_msg 
)

Creates a generic JSON-RPC error response string from the parameters passed, formatted with line breaks for easier readability.

Parameters:
$versionthe JSON-RPC version to include in the call
$idthe ID of the call
$error_msgthe parameters for the error response message/message payload
Returns:
a JSON string representing the JSON-RPC error response, formatted with line breaks for easier readability
Exceptions:
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeFormattedJSONRPCErrorString("1.0", $id, $error); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
JSON-RPC
string makeFormattedJSONRPCRequestString ( string  $method_name,
any  $version,
any  $id,
any  $request_msg 
)

Creates a JSON-RPC request string from the parameters passed, formatted with line breaks for easier readability.

To follow JSON-RPC specifications, the generated string will always be in UTF-8 encoding

Parameters:
$method_namethe name of the JSON-RPC method to call
$versionthe JSON-RPC version to include in the call
$idthe ID of the call
$request_msgthe parameters for the message/message payload
Returns:
a JSON string representing the JSON-RPC request, formatted with line breaks for easier readability
Exceptions:
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeFormattedJSONRPCRequestString("omq.system.help", "1.0", $id, $msg); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
JSON-RPC
string makeFormattedJSONRPCResponseString ( any  $version,
any  $id,
any  $response_msg 
)

Creates a JSON-RPC response string from the parameters passed, formatted with line breaks for easier readability.

Parameters:
$versionthe JSON-RPC version to include in the call
$idthe ID of the call
$response_msgthe parameters for the message/message payload
Returns:
a JSON string representing the JSON-RPC response, formatted with line breaks for easier readability
Exceptions:
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeFormattedJSONRPCResponseString("1.0", $id, $msg); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
JSON-RPC
string makeFormattedJSONString ( any  $data,
*string  $encoding 
)

Serializes qore data into a JSON string, formatted with line breaks for easier readability.

By default the string produced will be in UTF-8 encoding, but this can be overridden by the second argument

Parameters:
$datathe data to serialize to a JSON string
$encodingan optional output encoding for the resulting JSON string; if this argument is not passed, then the UTF-8 encoding is used by default
Returns:
the JSON string corresponding to the arguments passed, formatted with line breaks for easier readability
Exceptions:
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeFormattedJSONString($data); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
string makeJSONRPC11ErrorString ( softint  $code,
string  $error,
any  $id,
any  $error_msg 
)

Creates a JSON-RPC 1.1 error response string from the parameters passed, without any line breaks.

Parameters:
$codethe error code to return
$errora string error message
$idthe ID of the call
$error_msgthe parameters for the error response message/message payload
Returns:
a JSON string representing the JSON-RPC 1.1 error response, without any line breaks
Exceptions:
MAKE-JSONRPC11-ERROR-STRING-ERRORthe error code is not between 100-999 or empty error message string
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeJSONRPC11ErrorString(200, $msg, $id, $error); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
JSON-RPC
string makeJSONRPCErrorString ( any  $version,
any  $id,
any  $error_msg 
)

Creates a generic JSON-RPC error response string from the parameters passed, without any line breaks.

Parameters:
$versionthe JSON-RPC version to include in the call
$idthe ID of the call
$error_msgthe parameters for the error response message/message payload
Returns:
a JSON string representing the JSON-RPC error response, without any line breaks
Exceptions:
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeJSONRPCErrorString("1.0", $id, $error); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
JSON-RPC
string makeJSONRPCRequestString ( string  $method_name,
any  $version,
any  $id,
any  $request_msg 
)

Creates a JSON-RPC request string from the parameters passed, without any line breaks.

To follow JSON-RPC specifications, the generated string will always be in UTF-8 encoding

Parameters:
$method_namethe name of the JSON-RPC method to call
$versionthe JSON-RPC version to include in the call
$idthe ID of the call
$request_msgthe parameters for the message/message payload
Returns:
a JSON string representing the JSON-RPC request
Exceptions:
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeJSONRPCRequestString("omq.system.help", "1.0", $id, $msg); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
JSON-RPC
string makeJSONRPCResponseString ( any  $version,
any  $id,
any  $response_msg 
)

Creates a JSON-RPC response string from the parameters passed, without any line breaks.

Parameters:
$versionthe JSON-RPC version to include in the call
$idthe ID of the call
$response_msgthe parameters for the message/message payload
Returns:
a JSON string representing the JSON-RPC response, without any line breaks
Exceptions:
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeJSONRPCResponseString("1.0", $id, $msg); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
JSON-RPC
string makeJSONString ( any  $data,
*string  $encoding 
)

Serializes qore data into a JSON string, without any line breaks.

By default the string produced will be in UTF-8 encoding, but this can be overridden by the second argument

Parameters:
$datathe data to serialize to a JSON string
$encodingan optional output encoding for the resulting JSON string; if this argument is not passed, then the UTF-8 encoding is used by default
Returns:
the JSON string corresponding to the arguments passed, without any line breaks
Exceptions:
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Example:
 my string $json = makeJSONString($data); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
any parseJSON ( string  $json_string )

Parses a JSON string and returns the corresponding Qore data structure.

Parameters:
$json_stringthe JSON string to parse
Returns:
the Qore data structure corresponding to the input string
Exceptions:
JSON-PARSE-ERRORsyntax error parsing JSON string
Example:
 my any $data = parseJSONValue($json); 
Tags:
RET_VALUE_ONLY
See also:
Automatic JSON Serialization and Deserialization
nothing parseJSON (  )

This is a variant that is basically a noop, included for backwards-compatibility for functions that ignored type errors in the calling parameters.

Tags:
RUNTIME_NOOP
 All Classes Namespaces Files Functions