literalizer converts JSON, JSON5, YAML, and TOML data structures to native language literal syntax.
Ada, Bash, C, C#, C++, Clojure, COBOL, Common Lisp, Crystal, D, Dart, Dhall, Elixir, Elm, Erlang, F#, Forth, Fortran, Gleam, Go, Groovy, Haskell, Haxe, HCL, Java, JavaScript, JSON5, Jsonnet, Julia, Kotlin, Lua, MATLAB, Mojo, Nim, Nix, Norg, Objective-C, OCaml, Occam-pi, Odin, Perl, PHP, PowerShell, PureScript, Python, R, Racket, Raku, Roc, Ruby, Rust, Scala, Scheme, SML, Swift, SystemVerilog, Tcl, TOML, TypeScript, V, Visual Basic, Wren, YAML, Zig.
Requires Python 3.12+.
pip install literalizerPass 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 (backslash-t denotes a tab):
# map[string]any{
# \t// Server configuration
# \t"host": "localhost", // default host
# \t"port": 8080,
# \t"released": "2026-06-02",
# }- 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.
A command-line interface is available at literalizer-cli.
A Sphinx extension is available at sphinx-literalizer.
See the full documentation for more information including how to contribute.