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.1.tar.gz (37.5 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.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: literalizer-2026.3.15.1.tar.gz
  • Upload date:
  • Size: 37.5 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.1.tar.gz
Algorithm Hash digest
SHA256 ae0e2750900f147973bad3d4d42ca90b95226442ce0b71e95b0a6dc3cdd96614
MD5 7da532ed6220a1558b442036a34f4671
BLAKE2b-256 a2553f0b238f23f8d128b8f63ae826347fec368d274afa19379e2e8f338e54d9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for literalizer-2026.3.15.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c5a8a4acdfd4e064e3345639b5ac035889e77ddd2d4b2e0a610198b1492c4ac
MD5 c81386ab4496a3edbd33fcf5ef676ad9
BLAKE2b-256 1b2d0253e7b0cd90b2124f9c464db3124a13428b9dc809572a34c5aa5a65c38e

See more details on using hashes here.

Provenance

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