Skip to main content

Convert JSON data structures to native language literal syntax.

Project description

Build Status PyPI

literalizer

literalizer converts JSON data structures to native language literal syntax (Python, JavaScript, TypeScript, Go, Ruby, C#, C++, Java, Kotlin).

Installation

Requires Python 3.12+.

pip install literalizer

Usage examples

"""Examples of using literalizer."""

from literalizer import (
    JAVA,
    JAVASCRIPT,
    PYTHON,
    LanguageSpec,
    literalize,
    literalize_json,
    literalize_yaml,
)

# Convert a Python list to Java literal items
data = [True, None, "hi", [1, 2]]
result = literalize(
    data=data,
    language=JAVA,
    prefix="",
    wrap=False,
)
# result:
# true,
# null,
# "hi",
# {1, 2},

# Convert to JavaScript/TypeScript array
result = literalize(
    data=data,
    language=JAVASCRIPT,
    prefix="    ",
    wrap=True,
)
# result:
# [
#     true,
#     null,
#     "hi",
#     [1, 2],
# ]

# Convert from a JSON string directly
result = literalize_json(
    json_string='[true, null, "hi", [1, 2]]',
    language=PYTHON,
    prefix="",
    wrap=True,
)
# result:
# [
#     True,
#     None,
#     "hi",
#     (1, 2),
# ]

# Convert from a YAML string directly
result = literalize_yaml(
    yaml_string="- true\n- null\n- hi\n- [1, 2]",
    language=PYTHON,
    prefix="",
    wrap=True,
)
# result:
# [
#     True,
#     None,
#     "hi",
#     (1, 2),
# ]

# Built-in languages: PYTHON, JAVASCRIPT, TYPESCRIPT, GO, RUBY,
#                      CSHARP, CPP, JAVA, KOTLIN

# Create a custom language:
custom = LanguageSpec(
    null_literal="nil",
    true_literal="TRUE",
    false_literal="FALSE",
    collection_open="[",
    collection_close="]",
    dict_separator=": ",
)

Use cases

  • Generate test fixtures from JSON samples.

  • Convert API responses to language-native data structures for documentation.

  • Create type-safe literal data from JSON config files.

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.15.tar.gz (32.8 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.15-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: literalizer-2026.3.15.tar.gz
  • Upload date:
  • Size: 32.8 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.15.tar.gz
Algorithm Hash digest
SHA256 73427934f29fed0561337e5038c1fcba6238d35e21b4b1c001df6b19e1beada3
MD5 430a15c5fe0ac10f58f94d11d9587c25
BLAKE2b-256 46af44ea1f28e1479140d7f773f7780f05de6e56ec2e923a4fb0259281b34cda

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for literalizer-2026.3.15-py3-none-any.whl
Algorithm Hash digest
SHA256 51e3794714d42851e0efde6df4942cdea249805b2cd5bee3e5f265774dc1e6c2
MD5 353cd3bb45231a7afb86b8df90675ea6
BLAKE2b-256 7289b486c02e4c97e0906a441d4aa220effb413912db3c6826151820cf9e6b78

See more details on using hashes here.

Provenance

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