How to Convert JSON to XML Using the XML Object |
Starting with PxPlus 2025, JSON data can be easily converted to XML by using both the JSON (*obj/json) and XML (*obj/xml) objects.
The object programs, json.pvc and xml.pvc are found in the *lib/obj directory.
(The JSON object *OBJ/JSON was added in PxPlus 2025.)
These steps show you how to convert JSON data to XML by using the XML object.
|
1. |
Create both the JSON and XML objects. Example: json_obj=new("*obj/json") xml_obj=new("*obj/xml") |
|
2. |
Create JSON data using a string. Example: string$="{Address: ""Ontario"",StreetNum: 456}" |
|
3. |
Load the data into the JSON object. Example: json_obj'load_string(string$) Note:
|
|
4. |
Using the Print( ) method, you can print the JSON data Example: json_obj'print() |
|
5. |
Using the Load_json( ) method, load the XML data. Example: xml_obj'load_json(json_obj) |
|
6. |
To view the data you just created, print the XML string by using the Get_Xml$( ) method, which returns the XML string. Example: print xml_obj'get_xml$() |
|
7. |
Drop the json_obj and xml_obj objects. Example: drop object json_obj drop object xml_obj |
*OBJ/JSON - JSON Object
*OBJ/XML - XML Object
Associative Arrays (Hash Tables)
DIM Define Arrays and Strings
DIM( ) Generate String/Get Array Size
'JV' JSON Version