Skip to main content

Convert JSON data structures to native language literal syntax.

Project description

Build Status PyPI

literalizer

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

Supported languages

Ada, Bash, C, C#, C++, Clojure, COBOL, Common Lisp, Crystal, D, Dart, Elixir, Erlang, F#, Go, Groovy, Haskell, HCL, Java, JavaScript, Julia, Kotlin, Lua, MATLAB, Mojo, Nim, Norg, OCaml, Occam-pi, Perl, PHP, PowerShell, Python, R, Racket, Ruby, Rust, Scala, Swift, TOML, TypeScript, Visual Basic, Zig.

Installation

Requires Python 3.12+.

pip install literalizer

Usage

"""Example of using literalizer."""

from literalizer import literalize_yaml
from literalizer.languages import Go

# YAML comments are preserved using the target language's comment syntax
yaml_config = """\
# Server configuration
host: localhost  # default host
port: 8080
# Enable debug mode for development
debug: true
"""
result = literalize_yaml(
    yaml_string=yaml_config,
    error_on_coercion=False,
    language=Go(
        date_format=Go.date_formats.GO,
        datetime_format=Go.datetime_formats.GO,
        bytes_format=Go.bytes_formats.HEX,
        sequence_format=Go.sequence_formats.SLICE,
    ),
    pre_indent_level=0,
    include_delimiters=True,
    variable_name=None,
    new_variable=True,
)
# result:
# map[string]any{
#     // Server configuration
#     "host": "localhost",  // default host
#     "port": 8080,
#     // Enable debug mode for development
#     "debug": true,
# }

Use cases

  • Generate test fixtures from JSON or YAML samples.

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

  • Create type-safe literal data from JSON or YAML 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


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.3.30.tar.gz (663.9 kB view details)

Uploaded Source

Built Distribution

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

literalizer-2026.3.30-py3-none-any.whl (204.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: literalizer-2026.3.30.tar.gz
  • Upload date:
  • Size: 663.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for literalizer-2026.3.30.tar.gz
Algorithm Hash digest
SHA256 2b2ab69d3d57cb9fcf07bd8412e90f4a4f85bf66b5f05456ddaaed08a7c0b8b5
MD5 99dccfc2cddc8e9dbf7294f72b6ad028
BLAKE2b-256 6afda20a33e076b0013d64b8e2c583ab009e23464eff5a48aaf0bac05129b93a

See more details on using hashes here.

Provenance

The following attestation bundles were made for literalizer-2026.3.30.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.3.30-py3-none-any.whl.

File metadata

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

File hashes

Hashes for literalizer-2026.3.30-py3-none-any.whl
Algorithm Hash digest
SHA256 b89563bd10700865a3ce22c7639bbc48ec52934b4b28c679d0bfe6322a1a601a
MD5 0e8ff497ef19edd36b7821c83868e375
BLAKE2b-256 c90f0c3391d6395d8d490bc764c89c5f527d306c9c6c2f53f33c2b23e3fedb4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for literalizer-2026.3.30-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