JSON_Encode
System Library
Deprecated. This is now a wrapper for JSONEncode
| Description: | Takes a VTScada dictionary, structure or array which may be nested, and encodes it as JSON. |
| Returns: | Text |
Usage: ![]() |
Script Only. |
| Function Groups: | String and Buffer |
| Related to: | JSONParse |
Format: ![]() |
\System.JSON_Encode(Input[, PrettyPrint]) |
| Parameters: |
| Input |
| Required. Any stream expression for the socket. If this isn't a socket stream, invalid is returned. |
| PrettyPrint |
| Optional Boolean. If TRUE, the output will have white space and line breaks added for presentation. Default to FALSE. |
| Comments: |
The return value will be the input encoded as JSON. Text will be encoded as UTF-8, unless there are any sequences of bytes in the input string that cannot be represented as UTF-8, in which case the string will be substituted for JSON null. VTScada value types that are not dictionaries, arrays or structures, and that do not have a string or numeric representation, will be represented as JSON null. |
Example:
<
{============================== JSON_EncodeSample ==========================}
{ Example code to demonstrate System.JSON_Encode(). }
{===========================================================================}
JSON_EncodeSample
[
Protected Input { Input dictionary };
Protected JSONResult { Input encoded as JSON };
Protected PrettyPrintedResult { Pretty printed JSON result };
]
Main [
If Watch(1);
[
Input = Dictionary();
Input["Values" ] = New(3);
Input["Values" ][0] = 10;
Input["Values" ][1] = 20;
Input["Values" ][2] = 30;
Input["Timestamp"] = "2017-01-02T03:24:19Z";
JSONResult = \System.JSON_Encode(Input);
PrettyPrintedResult = \System.JSON_Encode(Input, TRUE);
]
]
{ End of JSON_EncodeSample }
>
JSONResult will be the following:
{"Values":[10,20,30],"Timestamp":"2017-01-02T03:24:19Z"}
PrettyPrintedResult will be the following:
{
"Values": [
10,
20,
30
],
"Timestamp": "2017-01-02T03:24:19Z"
}
