Skip to main content

Convert JSON data structures to native language literal syntax.

Project description

Build Status PyPI CodSpeed

literalizer

literalizer converts JSON, JSON5, YAML, and TOML data structures to native language literal syntax.

Supported languages

Ada, Bash, C, C#, C++, Clojure, COBOL, Common Lisp, Crystal, D, Dart, Dhall, Elixir, Elm, Erlang, F#, Fortran, Gleam, Go, Groovy, Haskell, Haxe, HCL, Java, JavaScript, JSON5, Jsonnet, Julia, Kotlin, Lua, MATLAB, Mojo, Nim, Norg, Objective-C, OCaml, Occam-pi, Odin, Perl, PHP, PowerShell, PureScript, Python, R, Racket, Raku, Roc, Ruby, Rust, Scala, Scheme, Swift, SystemVerilog, TOML, TypeScript, Visual Basic, YAML, Zig.

Installation

Requires Python 3.12+.

pip install literalizer

Usage

Pass your data, its format, and a target language:

"""Minimal example of using literalizer."""

from literalizer import InputFormat, literalize
from literalizer.languages import Python

result = literalize(
    source='{"x": 1}',
    input_format=InputFormat.JSON,
    language=Python(),
)
# result.code:
# {
#     "x": 1,
# }

Configure the language to control how individual data types are rendered. Comments in the source are preserved using the target language’s comment syntax:

"""Layering format options on top of the minimal call."""

from literalizer import InputFormat, literalize
from literalizer.languages import Go

yaml_config = """\
# Server configuration
host: localhost  # default host
port: 8080
released: 2026-06-02
"""
result = literalize(
    source=yaml_config,
    input_format=InputFormat.YAML,
    language=Go(date_format=Go.date_formats.ISO),
)
# result.code:
# map[string]any{
#     // Server configuration
#     "host": "localhost",  // default host
#     "port": 8080,
#     "released": "2026-06-02",
# }

Use cases

  • Generate test fixtures from JSON, JSON5, YAML, or TOML samples.

  • Generate multi-language request/response examples for API docs (see guide).

  • Generate multi-language function call examples from data (see guide).

  • Create type-safe literal data from JSON, JSON5, YAML, or TOML config files.

CLI

A command-line interface is available at literalizer-cli.

Full documentation

See the full documentation for more information including how to contribute.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

literalizer-2026.6.2.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

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

literalizer-2026.6.2-py3-none-any.whl (761.3 kB view details)

Uploaded Python 3

File details

Details for the file literalizer-2026.6.2.tar.gz.

File metadata

  • Download URL: literalizer-2026.6.2.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for literalizer-2026.6.2.tar.gz
Algorithm Hash digest
SHA256 881964fac745e570b55df49ec649a01a5242bc3a10477b97e7d44b91af03e1c3
MD5 7bc671b190a04426fae1421501ee5906
BLAKE2b-256 e91411aa9d1f92ec43116cb65b8ea85b8fc39a5d28d0fdfa0d0d70935d36a5ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for literalizer-2026.6.2.tar.gz:

Publisher: release.yml on adamtheturtle/literalizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file literalizer-2026.6.2-py3-none-any.whl.

File metadata

  • Download URL: literalizer-2026.6.2-py3-none-any.whl
  • Upload date:
  • Size: 761.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for literalizer-2026.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d1427edf0ebed6d6f3281aba5358e3b6338738a0cb4d575df927cf6120d125bf
MD5 6b69b9cc1cc876e1ee8da110e89500fe
BLAKE2b-256 378c86790808cf1084e23a589e1c451f9f4fa44ba59ac845dbd945fb493a8ab4

See more details on using hashes here.

Provenance

The following attestation bundles were made for literalizer-2026.6.2-py3-none-any.whl:

Publisher: release.yml on adamtheturtle/literalizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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