Edit and format JSON with ease

Convert XML and JSON from the command-line with JSONBuddy

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.

Where do I find the command-line tool?

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.

Convert from JSON to XML

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.

Convert from XML to JSON

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:

  • add-attribute-prefix : string
  • strip-namespace : boolean
  • colon-replace : string
  • transform-xsl : string, path to stylesheet
  • force-string-type : boolean
  • force-attributes-string-type : boolean
  • preserve-whitespace : boolean

Take a detailed look at some other features of JSONBuddy

JSONBuddy is more than just a JSON editor. Learn more on clicking the images and links below.