|
@@ -0,0 +1,64 @@
|
|
|
+<?xml version="1.0" encoding="UTF-8"?>
|
|
|
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
|
|
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
|
|
|
+<sect1 id="TOJSON">
|
|
|
+ <title>TOJSON</title>
|
|
|
+
|
|
|
+ <para><emphasis role="bold">TOJSON<indexterm>
|
|
|
+ <primary>TOJSON</primary>
|
|
|
+ </indexterm><indexterm>
|
|
|
+ <primary>TOJSON function</primary>
|
|
|
+ </indexterm>(</emphasis><emphasis> record </emphasis><emphasis
|
|
|
+ role="bold">)</emphasis></para>
|
|
|
+
|
|
|
+ <para><informaltable colsep="1" frame="all" rowsep="1">
|
|
|
+ <tgroup cols="2">
|
|
|
+ <colspec colwidth="77.95pt" />
|
|
|
+
|
|
|
+ <tbody>
|
|
|
+ <row>
|
|
|
+ <entry><emphasis>record</emphasis></entry>
|
|
|
+
|
|
|
+ <entry>The row (record) of data to convert to JSON format.</entry>
|
|
|
+ </row>
|
|
|
+
|
|
|
+ <row>
|
|
|
+ <entry>Return:</entry>
|
|
|
+
|
|
|
+ <entry>TOJSON returns a STRING.</entry>
|
|
|
+ </row>
|
|
|
+ </tbody>
|
|
|
+ </tgroup>
|
|
|
+ </informaltable></para>
|
|
|
+
|
|
|
+ <para>The <emphasis role="bold">TOJSON </emphasis>function returns a single
|
|
|
+ string with the data in the <emphasis>record</emphasis> re-formatted as
|
|
|
+ JSON. If the RECORD structure of the <emphasis>record</emphasis> has XPATHs
|
|
|
+ defined, then they will be used, otherwise the lower-cased field names are
|
|
|
+ used as the JSON tag names.</para>
|
|
|
+
|
|
|
+ <para>Example:</para>
|
|
|
+
|
|
|
+ <programlisting>namesRec1 := RECORD
|
|
|
+ UNSIGNED2 EmployeeID{xpath('EmpID')};
|
|
|
+ STRING10 Firstname{xpath('FName')};
|
|
|
+ STRING10 Lastname{xpath('LName')};
|
|
|
+END;
|
|
|
+str1 := TOJSON(ROW({42,'Fred','Flintstone'},namesRec1));
|
|
|
+OUTPUT(str1);
|
|
|
+//returns this string:
|
|
|
+//'"EmpID": 42, "FName": "Fred", "LName": "Flintstone"'
|
|
|
+namesRec2 := RECORD
|
|
|
+ UNSIGNED2 EmployeeID;
|
|
|
+ STRING10 Firstname;
|
|
|
+ STRING10 Lastname;
|
|
|
+END;
|
|
|
+str2 := TOJSON(ROW({42,'Fred','Flintstone'},namesRec2));
|
|
|
+OUTPUT(str2);
|
|
|
+//returns this string:
|
|
|
+//'"employeeid": 42, "firstname": "Fred", "lastname": "Flintstone"'
|
|
|
+</programlisting>
|
|
|
+
|
|
|
+ <para>See Also: <link linkend="ROW">ROW</link>, <link
|
|
|
+ linkend="FROMJSON">FROMJSON</link></para>
|
|
|
+</sect1>
|