Skip to main content

JSON → Anything converters (Python) — small, dependency-free helpers.

Project description

json_to_anything

PyPI version license

Python implementations of the JSON → Anything converters. Dependency-free helpers to convert simple JSON-like objects (dicts/lists) into CSV, YAML-like text, language-specific class definitions, SQL inserts, and more.

Highlights:

  • Package name: json_to_anything (see pip/setup.py)
  • License: MIT (see ../LICENSE)

Install (local)

From the project root, you can install locally into your environment:

cd pip
pip install .

Add metadata to setup.py (author, description, long_description, classifiers, python_requires, etc.) before publishing.

Quick usage

from json_any_endproduct import to_csv, to_yaml

data = [{"id":1, "name":"Alice"}, {"id":2, "name":"Bob"}]
print(to_csv(data))
print(to_yaml(data))

CLI usage

The package includes a lightweight cli() function in json_any_endproduct.__init__ which reads JSON from stdin and prints a conversion result. Example (default converter is to_csv):

echo '[{"a":1, "b":2}]' | python -c "from json_any_endproduct import cli; cli()"
# or explicitly specify function
echo '[{"a":1}]' | python -c "from json_any_endproduct import cli; import sys; sys.argv=['', 'to_yaml']; cli()"

To install a convenient command-line entry point, add to setup.py:

setup(
    name='json_any_endproduct',
    ...,
    entry_points={
        'console_scripts': [
            'json-any=json_any_endproduct:cli'
        ]
    }
)

After installing, you can run:

echo '[{"a":1}]' | json-any to_csv

API (selected functions)

  • to_yaml — simple YAML-like serializer
  • to_csv — CSV generator (headers from keys)
  • to_typescript — generates a TypeScript interface from an example object
  • to_js — pretty JSON (indentation)
  • to_schema_summary — key:type summary
  • to_html_table — basic HTML table
  • to_query / to_form_urlencoded — URL/query encoders
  • to_markdown_table — Markdown table
  • to_plantuml / to_mermaid — diagram skeletons
  • to_sql_insert / to_bash_export / to_csharp / to_java / to_python_dataclass / to_go_struct / to_rust_struct / to_dart_class / to_php_array / to_proto — language/format outputs

See pip/json_any_endproduct/__init__.py for the full implementations and limitations (these are intentionally small and naive implementations for quick conversions and prototyping).

License

This project is licensed under the MIT 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_anything-1.0.2.tar.gz (5.0 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_anything-1.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file json_to_anything-1.0.2.tar.gz.

File metadata

  • Download URL: json_to_anything-1.0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for json_to_anything-1.0.2.tar.gz
Algorithm Hash digest
SHA256 12e87314e3a37431b1553d6be3bac6d092a2a7795aa82bf56cf86d3c9316c608
MD5 b13817c20ec9f8d2040fbe27d954e4dd
BLAKE2b-256 0c28ed62baf1f583b27c4bef158e419e586c3d8b83b11596c17b7e5695a6805c

See more details on using hashes here.

File details

Details for the file json_to_anything-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for json_to_anything-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 efc78a2d4d1697e9e85756556307903217ee07fbdb98596420366a52460bb73c
MD5 ff26e4da079074e79523764d3cdf5ba6
BLAKE2b-256 1f10d917f25c640ae601ced8c62077d3fe012532346ef75cdd80ae907116cfab

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