New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

devkits-json-xml

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

devkits-json-xml

Convert between JSON and XML formats — bidirectional converter, zero dependencies

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

devkits-json-xml

Convert between JSON and XML formats. Bidirectional converter with zero dependencies.

Install

npm install -g devkits-json-xml

npm version

Usage

CLI

# JSON to XML
jsonxml to-xml '{"name":"Alice","age":30}'
jsonxml to-xml '{"items":[1,2,3]}' -r data

# XML to JSON
jsonxml to-json '<root><name>Alice</name></root>'

# Custom options
jsonxml to-xml '{"a":1}' -r custom -i 4

Programmatic API

const { jsonToXml, xmlToJson } = require('devkits-json-xml');

// JSON to XML
const xml = jsonToXml({ name: 'Alice', age: 30 });
console.log(xml);
// <root>
//   <name>Alice</name>
//   <age>30</age>
// </root>

// XML to JSON
const json = xmlToJson('<root><name>Alice</name></root>');
console.log(json);
// { root: { name: 'Alice' } }

// Custom root and indent
jsonToXml({ a: 1 }, 'data', '    ');

Conversion Rules

JSON → XML

JSONXML
{"key": "value"}<key>value</key>
{"key": 123}<key>123</key>
{"key": null}<key/>
{"key": []}<key/>
{"key": [1,2]}<key><item>1</item><item>2</item></key>
Nested objectsNested elements

XML → JSON

XMLJSON
<key>value</key>{ key: "value" }
<key>123</key>{ key: 123 }
<key/>{ key: "" }
<key attr="1"/>{ key: { "@attr": "1" } }
<a><b>1</b></a>{ a: { b: 1 } }

Options

OptionAliasDefaultDescription
--root-rrootRoot element name
--indent-i2Indentation spaces

Examples

# Simple object
$ jsonxml to-xml '{"name":"DevKits"}'
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <name>DevKits</name>
</root>

# Nested object
$ jsonxml to-xml '{"user":{"name":"Alice","age":30}}'
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <user>
    <name>Alice</name>
    <age>30</age>
  </user>
</root>

# Array
$ jsonxml to-xml '{"items":[1,2,3]}'
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <items>
    <item>1</item>
    <item>2</item>
    <item>3</item>
  </items>
</root>

# XML to JSON
$ jsonxml to-json '<user><name>Alice</name><age>30</age></user>'
{
  "user": {
    "name": "Alice",
    "age": 30
  }
}

Use Cases

  • API integration — Convert between REST (JSON) and SOAP (XML) APIs
  • Data migration — Transform legacy XML data to JSON
  • Configuration — Convert config files between formats
  • Testing — Generate test data in different formats
  • ETL pipelines — Process data from XML sources to JSON targets

Features

  • Bidirectional — Both JSON→XML and XML→JSON
  • Type preservation — Numbers, booleans detected automatically
  • Attribute support — XML attributes prefixed with @
  • Nested structures — Full support for nested objects/arrays
  • Custom root — Configurable root element name
  • Pretty printing — Configurable indentation

🔍 Build something amazing? Check out API Monitor — simple, affordable API monitoring for indie hackers. Get alerted before your customers notice. Just $9/mo.

See Also

Support DevKits

If you find this tool useful, please consider supporting the project:

Open Collective

Become a sponsor: Open Collective - DevKits

Crypto Donations

Prefer crypto? We accept:

  • ETH (Ethereum): 0xDea4a6A20fCB44467e45Ef378972F54B22dC59db
  • USDC (ERC-20): 0xDea4a6A20fCB44467e45Ef378972F54B22dC59db

Donation Perks:

  • $5+ — Supporter Badge
  • $10+ — Pro Access (1 month)
  • $29+ — Pro Access (1 year)
  • $100+ — Lifetime Pro + Priority Support

After donating, email your transaction hash to devkits@aiforeverthing.com to claim perks.

View Crypto Donation Page

License

MIT — DevKits Team

Keywords

devkits

FAQs

Package last updated on 12 Mar 2026

Related posts