npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polyconv/json

v0.3.1

Published

TypeScript JSON converter utilities for JSON to XML, YAML, TOML, CSV, TSV, INI, ENV, Markdown, HTML, and query strings.

Readme

@polyconv/json

TypeScript JSON converter and formatting utilities for Polyconv. Convert JSON strings to XML, YAML, TOML, CSV, TSV, INI, ENV, Markdown tables, HTML tables, and URL query strings, or format and minify JSON.

npm version License

Installation

pnpm add @polyconv/json

This package is ESM-only and requires Node.js 22+.

Features

  • Convert JSON to XML with customizable options
  • Convert JSON to YAML with formatting control
  • Convert JSON to TOML
  • Convert JSON to CSV, TSV, Markdown tables, and HTML tables
  • Convert JSON objects to INI, ENV, and URL query strings
  • Format and minify JSON
  • Tree-shakeable exports
  • Full TypeScript support
  • XML and YAML are built on battle-tested libraries (fast-xml-builder, js-yaml)

Usage

JSON to XML

import { jsonToXml, JsonToXmlConverter } from "@polyconv/json";

const json = '{"users": [{"name": "Alice", "age": 30}]}';

const xml = jsonToXml(json);

const prettyXml = jsonToXml(json, {
  rootName: "data",
  pretty: true,
  indent: 2,
  ignoreAttributes: false,
});

// Using the converter class
const converter = new JsonToXmlConverter();
const result = converter.convert(json, { pretty: true });
console.log(result.data); // XML string
console.log(result.format); // "xml"

JSON to YAML

import { jsonToYaml, JsonToYamlConverter } from "@polyconv/json";

const json = '{"name": "polyconv", "version": "1.0.0"}';

const yaml = jsonToYaml(json);

const sortedYaml = jsonToYaml(json, {
  indent: 2,
  lineWidth: 80,
  sortKeys: true,
  pretty: true,
});

// Using the converter class
const converter = new JsonToYamlConverter();
const result = converter.convert(json, { sortKeys: true });

JSON to TOML

import { jsonToToml, JsonToTomlConverter } from "@polyconv/json";

const json = '{"name":"polyconv","config":{"enabled":true}}';

const toml = jsonToToml(json, {
  sortKeys: true,
});

const converter = new JsonToTomlConverter();
const result = converter.convert(json);

JSON to CSV / TSV

import { jsonToCsv, jsonToTsv } from "@polyconv/json";

const json = '[{"name":"Alice","age":30},{"name":"Bob","active":true}]';

const csv = jsonToCsv(json);
const tsv = jsonToTsv(json, { sortKeys: true });

JSON to Tables

import { jsonToMarkdownTable, jsonToHtmlTable } from "@polyconv/json";

const json = '[{"name":"Alice","status":"active"}]';

const markdown = jsonToMarkdownTable(json);
const html = jsonToHtmlTable(json);

JSON to INI / ENV / Query String

import { jsonToEnv, jsonToIni, jsonToQueryString } from "@polyconv/json";

const ini = jsonToIni('{"name":"polyconv","config":{"enabled":true}}');
const env = jsonToEnv('{"NAME":"polyconv","PORT":3000}');
const query = jsonToQueryString('{"q":"hello world","tag":["a","b"]}');

Format JSON

import { formatJson, minifyJson } from "@polyconv/json";

const json = '{"name":"polyconv","version":"1.0.0"}';

const formatted = formatJson(json, {
  indent: 4,
  sortKeys: true,
});

const minified = minifyJson(json);

API

JSON to XML

jsonToXml(input: string, options?: JsonToXmlOptions): string

interface JsonToXmlOptions {
  rootName?: string;              // Root element name (default: "root")
  pretty?: boolean;               // Pretty print (default: false)
  indent?: number;                // Indentation size (default: 2)
  ignoreAttributes?: boolean;     // Ignore attributes (default: false)
  attributeNamePrefix?: string;   // Attribute prefix (default: "@_")
  textNodeName?: string;          // Text node name (default: "#text")
  cdataTagName?: string;          // CDATA tag name
}

JSON to YAML

jsonToYaml(input: string, options?: JsonToYamlOptions): string

interface JsonToYamlOptions {
  pretty?: boolean;      // Pretty print (default: false)
  indent?: number;       // Indentation size (default: 2)
  lineWidth?: number;    // Max line width (default: 80)
  flowLevel?: number;    // Flow style level
  sortKeys?: boolean;    // Sort object keys (default: false)
  skipInvalid?: boolean; // Skip invalid values (default: false)
}

JSON to TOML

jsonToToml(input: string, options?: JsonToTomlOptions): string

interface JsonToTomlOptions {
  pretty?: boolean;
  indent?: number;
  sortKeys?: boolean; // Sort object keys (default: false)
}

JSON to CSV / TSV / Markdown / HTML Table

jsonToCsv(input: string, options?: JsonToDelimitedOptions): string
jsonToTsv(input: string, options?: JsonToDelimitedOptions): string
jsonToMarkdownTable(input: string, options?: JsonToMarkdownTableOptions): string
jsonToHtmlTable(input: string, options?: JsonToHtmlTableOptions): string

interface JsonToDelimitedOptions {
  sortKeys?: boolean; // Sort table headers (default: false)
}

These table converters accept one plain object or an array of plain objects. Cell values must be strings, numbers, booleans, or null.

JSON to INI / ENV / Query String

jsonToIni(input: string, options?: JsonToIniOptions): string
jsonToEnv(input: string, options?: JsonToEnvOptions): string
jsonToQueryString(input: string, options?: JsonToQueryStringOptions): string

interface JsonToIniOptions {
  sortKeys?: boolean;
}

interface JsonToEnvOptions {
  sortKeys?: boolean;
}

interface JsonToQueryStringOptions {
  sortKeys?: boolean;
}

INI and ENV accept top-level objects. Query strings accept scalar values and arrays of scalar values, emitting repeated keys for arrays.

Format & Minify

formatJson(input: string, options?: FormatOptions): string
minifyJson(input: string): string

interface FormatOptions {
  indent?: number;      // Indentation size (default: 2)
  sortKeys?: boolean;   // Sort object keys (default: false)
}

Error Handling

import { jsonToXml } from "@polyconv/json";
import { ConversionError } from "@polyconv/core";

try {
  const xml = jsonToXml(invalidJson);
} catch (error) {
  if (error instanceof ConversionError) {
    console.error(`Conversion failed: ${error.toString()}`);
    console.error(`Source: ${error.sourceFormat}`);
    console.error(`Target: ${error.targetFormat}`);
  }
}

Input Contract

All helpers accept JSON as a string and throw ConversionError for invalid or empty input. Parse JSON into an object yourself only if you need to validate or transform the data before calling these helpers.

License

MIT