Skip to main content

A utility package to convert JSON data to multiple formats like XML, Markdown, CSV, etc.

Project description

Json2Many

PyPI Version License

A zero-dependency Python library and CLI for converting JSON into multiple output formats. Every conversion returns a typed ConversionResult — no raw string parsing, full mypy/pyright support out of the box.

User Guide — scenario-driven walkthrough of every feature

demo


Installation

# Library only
pip install json_to_many

# With CLI support
pip install 'json_to_many[cli]'

Quick Start

Library:

from json_to_many import convert

result = convert("users.json", "csv", delimiter=";")
print(result.data)
# id,name,email,score,city
# 1,Alice Nguyen,alice@example.com,8.4,London
# 2,Bob Smith,bob@example.com,7.1,Berlin
print(result.stats.rows)    # 5

convert() also accepts Pydantic models, dataclasses, and any object exposing to_dict() — single instances or lists, including nested fields:

from dataclasses import dataclass
from pydantic import BaseModel
from json_to_many import convert

class User(BaseModel):
    id: int
    name: str

@dataclass
class Order:
    id: int
    total: float

convert([User(id=1, name="Alice"), User(id=2, name="Bob")], "csv")
convert([Order(id=10, total=42.5)], "markdown")

Pydantic v1? Pass .dict() yourself — only v2's model_dump() is auto-detected.

CLI:

# Inspect a JSON file before converting
json2many schema api_export.json

# Convert to CSV
json2many convert api_export.json --to csv --output report.csv

# Multiple formats in one pass
json2many convert api_export.json --to csv --to html --output-dir ./dist/

Formats

Format When to use Options
markdown Docs, wikis, changelogs title, heading_offset, max_heading_level, bullet_lists, table_for_lists, frontmatter, code_block_keys
xml Legacy system integration, data exchange root_element, item_element, pretty_print
csv Spreadsheets, analyst handoff delimiter, quotechar, include_header, columns
html Stakeholder reports, CI build artifacts title, table_style, wrap_in_page
jsonl Log pipelines, ML fine-tuning, streaming ensure_ascii
sql Database seeding, fixture data for tests table, include_create, batch_size

Project Config

Add .json2many.toml at your project root to share converter settings across a team:

[converters.csv]
delimiter = ";"

[converters.xml]
pretty_print = true
root_element = "records"

Explicit options always override the config file. See the User Guide for the full priority order and all supported keys.


Development

uv sync --extra cli --dev       # install runtime, CLI, and dev tooling
uv run pre-commit install       # install Git hooks
uv run pre-commit run --all-files
uv run pytest

The pre-commit setup runs Ruff lint fixes, Ruff formatting, YAML validation, trailing whitespace cleanup, and final newline checks. Ruff is pinned through both pyproject.toml and .pre-commit-config.yaml; keep those versions aligned when upgrading the formatter.

Maintainers: See RELEASING.md for the release process.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_to_many-0.5.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_to_many-0.5.0-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file json_to_many-0.5.0.tar.gz.

File metadata

  • Download URL: json_to_many-0.5.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for json_to_many-0.5.0.tar.gz
Algorithm Hash digest
SHA256 d82b0c9e9dfae71bd4024f789ecfb87121b05d88975d39bd2829c43d4c1cb610
MD5 2b7fa3220cc5eed01a9931f419748493
BLAKE2b-256 bbbd727b14bd8b9a6edc64bf47f18824d024c29dcd8305738e32aa1963caad2b

See more details on using hashes here.

File details

Details for the file json_to_many-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for json_to_many-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce13dc7024d9012bdd0501d8dcf56838d3ab7d88bdd60e372212fb1da62f6cea
MD5 151685619003160c52bff2d88da31262
BLAKE2b-256 9a8370a6dde964659b35ee1a66a0f4201cdb1ae9f805dca4975d0d5e992ac3de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page