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.6.0.tar.gz (25.9 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.6.0-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for json_to_many-0.6.0.tar.gz
Algorithm Hash digest
SHA256 a2b93b4d86ff4405853bf2903583b5ea5cc005851130f3619610eb5c1899a537
MD5 f7f79cde6fff65ad16a8c138dc1f7f33
BLAKE2b-256 fd82319166c0115fb0a605d84c3a8fcc773bb07a37acce535c19f07e3279d40c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for json_to_many-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9943c0fc2b6b195763f7e6d1b84c4e2d2c2c3a38ff95af7078466e7d2edff70
MD5 27afcc8934276f1cf00aba06224214e7
BLAKE2b-256 7aff0866d8b572c0aadaf4ad0ee385594b1a45d515f47a5c560645c7045f5d85

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