Nestedtextto
CLI to convert between NestedText and JSON, YAML, or TOML, with explicit type casting
Install / Use
/learn @AndydeCleyre/NestedtexttoREADME
NestedTextTo
CLI to convert between NestedText and JSON, YAML, HUML, or TOML, with explicit type casting
This project was created in appreciation for the design of NestedText, the readability of yamlpath queries, the utility of cattrs, and the joy of plumbum and ward -- none of which are this author's projects.
This project, NestedTextTo, provides command line tools for convenient conversion between NestedText and other formats:
-
nt2with subcommands:json,yaml,toml,humlnt2 {json,toml,yaml}can also be invoked as a single command:nt2json,nt2toml,nt2yaml
-
2ntwith subcommands:json,yaml,toml,huml2nt {json,toml,yaml}can also be invoked as a single command:json2nt,toml2nt,yaml2nt
<!--TOC-->
- What's NestedText?
- How does this translate to formats with more value types?
- Installation
- Usage Docs
- More Examples
- Development Docs
What's NestedText?
From the NestedText docs, with emphasis added:
NestedText is a file format for holding structured data to be entered, edited, or viewed by people. It organizes the data into a nested collection of dictionaries, lists, and strings without the need for quoting or escaping. A unique feature of this file format is that it only supports one scalar type: strings. While the decision to eschew integer, real, date, etc. types may seem counter intuitive, it leads to simpler data files and applications that are more robust.
How does this translate to formats with more value types?
When converting from NestedText to formats supporting more value types, all plain values will be strings by default. But you can provide options to cast any values as numbers, booleans, nulls, or dates/times, if the target format supports it, using the powerful and concise YAML Path query syntax.
$ cat config.nt
logging:
level: info
file: /var/log/app.log
rotate: yes
max_size: 100
$ nt2json config.nt --number logging.max_size --boolean logging.rotate
{
"logging": {
"level": "info",
"file": "/var/log/app.log",
"rotate": true,
"max_size": 100
}
}
You may instead store these type mappings in a NestedText "schema" file.
$ cat config.types.nt
boolean:
- logging.rotate
number:
- logging.max_size
The following command will then also yield the above JSON:
$ nt2json config.nt --schema config.types.nt
Such a schema may be automatically generated from any of the typed formats:
$ json2nt --to-schema config.json
Options may be provided before or after the document, and content may be piped directly to the command instead of specifying a file.
For more YAML Path syntax information see the YAML Path wiki.
For example, you could match all items which are probably intended as booleans,
at any depth, with --boolean '**[. =~ /(?i)^(yes|no|true|false)$/]'.
Installation
Support for JSON and YAML are always included.
If you don't need support for more than those, you can omit the [all] bits below.
Or you can use a comma-separated list of extra formats, like [toml,huml].
Here are some ways to install it:
$ uv tool install 'nt2[all]' # Install using uv (Python all-around manager)
$ pipx install 'nt2[all]' # Install using pipx (Python app manager)
$ pipz install 'nt2[all]' # Install using zpy (Python app and environment manager for Zsh)
$ pip install --user 'nt2[all]' # Install in your user's environment
$ pip install 'nt2[all]' # Install in current environment
I recommend using uv,
pipx,
or pipz from zpy.
Shell Completion
For Zsh completion, add this line to your .zshrc, any time after compinit:
compdef _gnu_generic nt2{json,{to,ya}ml} {json,{to,ya}ml}2nt
Usage Docs
<details> <summary>nt2</summary>nt2 0.3.0
Convert NestedText to another format.
Examples:
- nt2 json config.nt
- nt2 json config.nt --number font.size --boolean font.bold
- nt2 json config.nt --schema config.types.nt
- cat config.nt | nt2 json
Usage:
nt2 [SWITCHES] [SUBCOMMAND [SWITCHES]] args...
Meta-switches:
-h, --help Prints this help message and quits
--help-all Prints help messages of all sub-commands and quits
-v, --version Prints the program's version and quits
Sub-commands:
completion Print completion code for the given shell.
hjson Read NestedText and output its content as Hjson.
huml Read NestedText and output its content as HUML.
json Read NestedText and output its content as JSON.
maml Read NestedText and output its content as MAML.
toml Read NestedText and output its content as TOML.
xml Read NestedText and output its content as XML.
yaml Read NestedText and output its content as YAML.
</details>
<details>
<summary>2nt</summary>
2nt 0.3.0
Convert another format to NestedText.
Examples:
- 2nt config.json
- 2nt config.json --to-schema >config.types.nt
- cat config.json | 2nt json
- cat config.json | 2nt --from json
Usage:
2nt [SWITCHES] [SUBCOMMAND [SWITCHES]] DATA_FILE...
Meta-switches:
-h, --help Prints this help message and quits
--help-all Prints help messages of all sub-commands and
quits
-v, --version Prints the program's version and quits
Switches:
--from, -f FROM_FORMAT:{maml, hjson, huml, toml, yml, yaml, json, jsonl, xml}
Format to convert from
--inline-width, -i WIDTH:[0..120] Maximum line width for inline dictionaries
and lists
--to-schema, -s Rather than convert the inputs, generate a
schema
Sub-commands:
completion Print completion code for the given shell.
hjson Read Hjson and output its content as
NestedText.
huml Read HUML and output its content as
NestedText.
json Read JSON and output its content as
NestedText.
maml Read MAML and output its content as
NestedText.
toml Read TOML and output its content as
NestedText.
xml Read XML and output its content as
NestedText.
yaml Read YAML and output its content as
NestedText.
</details>
<details>
<summary>nt2 json</summary>
nt2 json 0.3.0
Read N
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
96.8kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
344.1kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
