Save time and run batch tasks to convert between XML and JSON for any number of input documents using the command line tool included in JSONBuddy.
Quickly convert any number of JSON and XML files or create a scheduled task which runs as a batch process (on your server). This page shows you in more detail how to create the configuration files to convert between XML and JSON from the command line.
The name of the executable is "valbuddy.exe" and it is located in the standard installation folder of JSONBuddy. The installer also adds the path to the JSONBuddy installation folder to the PATH environment variable.
As usual the command-line tool needs a configuration XML to run the conversion as batch task. You can specify the folder and any number of file extensions to identify your JSON data. The following sample shows how to create the configuration XML to convert all JSON documents located in the folder "D:\Documents\JSON". The batch task will also scan any sub-folders (attribute subfolders="true" of the folder_settings elements). Use the type attribute of the "batch_unit" element and set the value to "json2xml" to run the task for the conversion from JSON to XML.
<?xml version="1.0" encoding="UTF-8"?> <batch_settings> <batch_units> <log_document path="D:\Documents\convert_json_log.xml"/> <options notify_finish="false" omit_results="false" omit_time="false" run_as_test="false" save_logdoc="true" timeout="-1" use_xmldate_format="true"/> <batch_unit output_folder="D:\Documents\XML-converted" overwrite="true" type="json2xml"> <folder_settings folder="D:\Documents\JSON" subfolders="true"/> <file_extensions> <extension>json</extension> </file_extensions> </batch_unit> </batch_units> </batch_settings>
Use the file_extensions element to set a list of file extensions which should be included on converting the JSON input.
Once you have created a configuration XML to set the options and parameters for the JSON to XML conversion you can call the command line tool in the following way:
valbuddy.exe myJSON2XMLconfig.xml
If you don’t specify an output folder using the "output_folder" attribute, the resulting XML files are written next to the JSON input documents. Any folder structure from the source directory is also copied to the output folder. You can also set the overwrite attribute to overwrite="true" or "false" of the "batch_unit" element to control if any already existing output documents are replaced.
Use the command-line tool in a similar way to convert from XML to JSON:
<?xml version="1.0" encoding="UTF-8"?> <batch_settings> <batch_units> <log_document path="D:\Documents\convert_xml_json_log.xml"/> <options notify_finish="false" omit_results="false" omit_time="false" run_as_test="false" save_logdoc="true" timeout="-1" use_xmldate_format="true"/> <batch_unit output_folder="D:\Documents\JSON-converted" overwrite="true" type="xml2json"> <folder_settings folder="D:\Documents\XML" subfolders="true"/> <file_extensions> <extension>xml</extension> </file_extensions> <parameters add-attribute-prefix="@" force-string-type="true"></parameters> </batch_unit> </batch_units> </batch_settings>
Set the value of the type attribute of the "batch_unit" element to "xml2json" to convert XML data to JSON.
The following options are supported as attributes of the <parameters> element:
JSONBuddy is more than just a JSON editor for Windows ®. Learn more on clicking the images and links below.
See in detail how your JSON data is validated using the JSON Schema validation debugger.
Try hereXML, JSON, CSV and HTML conversion tool. Import CSV text and get JSON, XML or HTML.
Read MoreUse the streaming JSON formatter to get pretty JSON.
Verify how a set of data files align with your JSON Schema resources. Easy and automated.
Get a complete JSON Schema designer with extended support for creating and testing JSON schema specifications.
Read MoreImport from any CSV text and get structured JSON or XML data in the editor.
Read MoreJSON editor with built-in JSON pointer engine. Useful on creating JSON Schema documents and for navigation.