# How to Convert XML to JSON

> Source: https://manual.pvxplus.com/how-to/how-to-convert-xml-to-json

Starting with PxPlus 2025, XML data can be easily converted to JSON by using the **[XML Object](https://manual.pvxplus.com/utilities/obj-xml)** (\*obj/xml). The object programs, ***json.pvc*** and ***xml.pvc*** are found in the ***\*lib/obj*** directory.

These steps show you how to set up XML data and then convert the XML data to JSON.

## Set Up XML Data

These steps show you how to set up XML data.

|  |  |  |
| --- | --- | --- |
|  | 1\. | Create both the JSON and XML objects.<br>***Example:***<br>json_obj=new("\*obj/json")<br>xml_obj=new("\*obj/xml") |
|  | 2\. | Using the **Set_Xml( )** method, load and create nodes in a given XML string.<br>***Example:***<br>xml_obj'set_xml("\<emp>\<name>John Smith\</name>\<addr>456 Ontario Street\</addr>\<age>40\</age>\</emp>") |
|  | 3\. | To view the data you just created, you can print the XML string by using the **Get_Xml$( )** method, which returns the XML string.<br>***Example:***<br>print xml_obj'get_xml$()<br>![](https://manual.pvxplus.com/migration-assets/9efb8d2d510b5166b01346a5a4de2de1b3c036c1fa5643768b5838a541f43f52.png) |

## Convert XML Data to JSON Format (without numeric conversion)

Note:  
By default, when converting data, JSON auto converts strings to numeric.

These steps show you how to convert XML data to JSON format.

|  |  |  |
| --- | --- | --- |
|  | 1\. | Load the XML data you created above.<br>***Example:***<br>json_obj'load_xml(xml_obj) |
|  | 2\. | Using the **Print( )** method, you can print the JSON data<br>***Example:***<br>json_obj'print()<br>![](https://manual.pvxplus.com/migration-assets/723ca405f3d08fe46f00009ddc82823738f54e949a267da97af0dbc382132d3e.png) |
|  | 3\. | If you want to load the XML object ***without numeric conversion***, then the examples for Step 1 and Step 2 would look like this:<br>***Example:***<br>json_obj'load_xml(xml,0)<br>Using the **Print( )** method, you can print the JSON data.<br>***Example:***<br>json_obj'print()<br>![](https://manual.pvxplus.com/migration-assets/676a2a1c7a5654fc3dae19e5490e2d3f0f26bbff39abb5504169626d0f722256.png) |
|  | 4\. | Drop the **json_obj** and **xml_obj** objects.<br>***Example:***<br>drop object json_obj<br>drop object xml_obj |

## See Also

**[\*OBJ/XML - XML Object](https://manual.pvxplus.com/utilities/obj-xml)  
[\*OBJ/JSON - JSON Object](https://manual.pvxplus.com/utilities/obj-json)  
[Associative Arrays (Hash Tables)](https://manual.pvxplus.com/pxplus-user-guide/language-elements/data-types-literals-and-variables/associative-arrays-hash-tables)**  
**[DIM Define Arrays and Strings](https://manual.pvxplus.com/directives/dim)**  
**[DIM( ) Generate String/Get Array Size](https://manual.pvxplus.com/functions/dim)**  
**['JV' JSON Version](https://manual.pvxplus.com/parameters/jv)**
