Name | nt2 JSON |
Version |
0.2.7
JSON |
| download |
home_page | None |
Summary | CLI to convert between NestedText and JSON, YAML or TOML, with explicit type casting. |
upload_time | 2024-10-15 20:07:19 |
maintainer | None |
docs_url | None |
author | Andy Kluger |
requires_python | >=3.7 |
license | None |
keywords |
nestedtext
json
yaml
toml
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# NestedTextTo
## CLI to convert between NestedText and JSON, YAML or TOML, with explicit type casting
![Python versions](https://img.shields.io/pypi/pyversions/nt2?logo=python)
[![PyPI version](https://img.shields.io/pypi/v/nt2?logo=pypi&label=PyPI&color=yellowgreen)](https://pypi.org/project/nt2/)
[![Publish to PyPI](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/pypi.yml?label=Publish%20to%20PyPI&logo=github)](https://github.com/AndydeCleyre/nestedtextto/actions/workflows/pypi.yml)
![Runs on Linux](https://img.shields.io/badge/Runs%20on-Linux-yellowgreen?logo=linux)
![Runs on macOS](https://img.shields.io/badge/Runs%20on-macOS-red?logo=macos)
![Runs on Windows](https://img.shields.io/badge/Runs%20on-Windows-blue?logo=windows)
[![Tests badge](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/test.yml?branch=develop&label=Tests&logo=github)](https://github.com/AndydeCleyre/nestedtextto/actions/workflows/test.yml)
[![codecov badge](https://codecov.io/github/AndydeCleyre/nestedtextto/branch/develop/graph/badge.svg?token=M30UZQVM4Q)](https://codecov.io/github/AndydeCleyre/nestedtextto)
[![Format and lint](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/fmt.yml?branch=develop&label=Format%20%26%20Lint&logo=github)](https://github.com/AndydeCleyre/nestedtextto/actions/workflows/fmt.yml)
[![Generate docs from templates](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/doc.yml?branch=develop&label=Make%20Docs&logo=github)](https://andydecleyre.github.io/nestedtextto/moduleIndex.html)
[![Requirements badge](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/reqs.yml?branch=develop&label=Bump%20Reqs&logo=github)](https://github.com/AndydeCleyre/nestedtextto/actions/workflows/reqs.yml)
<img src="https://github.com/AndydeCleyre/nestedtextto/blob/assets/logo.png?raw=true" alt="logo" width="160" height="160" />
This project was created in appreciation for the design of [NestedText](https://nestedtext.org/),
the readability of [yamlpath](https://github.com/wwkimball/yamlpath) queries,
the utility of [cattrs](https://cattrs.readthedocs.io/),
and the joy of [plumbum](https://plumbum.readthedocs.io/)
and [ward](https://ward.readthedocs.io/) --
none of which are this author's projects.
This project, NestedTextTo, provides six command line tools
for convenient conversion between NestedText and other formats:
- `nt2json`, `nt2toml`, `nt2yaml`
- `json2nt`, `toml2nt`, `yaml2nt`
---
<!--TOC-->
- [What's NestedText?](#whats-nestedtext)
- [How does this translate to formats with more value types?](#how-does-this-translate-to-formats-with-more-value-types)
- [Installation](#installation)
- [Shell Completion](#shell-completion)
- [Usage Docs](#usage-docs)
- [Limitations](#limitations)
- [More Examples](#more-examples)
- [View JSON Lines logs in a more readable format](#view-json-lines-logs-in-a-more-readable-format)
- [View TOML as NestedText](#view-toml-as-nestedtext)
- [Convert NestedText to TOML, with and without casting](#convert-nestedtext-to-toml-with-and-without-casting)
- [Convert NestedText to TOML with casting via auto-schema](#convert-nestedtext-to-toml-with-casting-via-auto-schema)
- [Query TOML with JSON tools, with and without casting](#query-toml-with-json-tools-with-and-without-casting)
- [Development Docs](#development-docs)
<!--TOC-->
---
### 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.
```console
$ cat example.nt
```
```yaml
people:
-
name: Bill Sky
problems: 99
happy: False
-
name: Vorbis Florbis
problems: 6
happy: yes
```
```console
$ nt2json example.nt --number /people/problems --boolean /people/happy
```
```json
{
"people": [
{
"name": "Bill Sky",
"problems": 99,
"happy": false
},
{
"name": "Vorbis Florbis",
"problems": 6,
"happy": true
}
]
}
```
You may instead store these type mappings in a NestedText "schema" file.
```console
$ cat example.types.nt
```
```yaml
boolean:
- /people/happy
number:
- /people/problems
```
The following command will then also yield the above JSON:
```console
$ nt2json example.nt --schema example.types.nt
```
Such a schema may be automatically generated from JSON/TOML/YAML:
```console
$ json2nt --to-schema example.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](https://github.com/wwkimball/yamlpath/wiki/Search-Expressions).
For example, you could match all items which are *probably* intended as booleans,
at any depth, with `--boolean '/**[.=~/^(?i)(yes|no|true|false)$/]'`.
### Installation
If you don't need TOML support, you can omit the `[toml]` bits below.
Here are some ways to install it:
```console
$ uv tool install 'nt2[toml]' # Install using uv (Python all-around manager)
$ pipx install 'nt2[toml]' # Install using pipx (Python app manager)
$ pipz install 'nt2[toml]' # Install using zpy (Python app and environment manager for Zsh)
$ pip install --user 'nt2[toml]' # Install in your user's environment
$ pip install 'nt2[toml]' # Install in current environment
```
I recommend using [uv](https://github.com/astral-sh/uv),
[pipx](https://github.com/pypa/pipx),
or `pipz` from [zpy](https://github.com/AndydeCleyre/zpy).
#### Shell Completion
For Zsh completion, add this line to your `.zshrc`, any time after `compinit`:
```zsh
if (( $+functions[compdef] )) && (( $+commands[nt2json] )) compdef _gnu_generic nt2yaml nt2toml nt2json json2nt toml2nt yaml2nt
```
### Usage Docs
<details>
<summary>nt2json</summary>
```
nt2json 0.2.7
Read NestedText and output its content as JSON.
By default, generated JSON values will only contain strings, arrays, and maps,
but you can cast nodes matching YAML Paths to boolean, null, or number.
Casting switches may be before or after file arguments.
Examples:
nt2json example.nt
nt2json <example.nt
cat example.nt | nt2json
nt2json --int People.age --boolean 'People."is a wizard"' example.nt
Usage:
nt2json [SWITCHES] input_files...
Meta-switches:
-h, --help Prints this help message and quits
-v, --version Prints the program's version and quits
Switches:
--boolean, -b YAMLPATH:str Cast each node matching the given YAML Path
query as boolean; may be given multiple
times
--null, -n YAMLPATH:str Cast each node matching the given YAML Path
query as null, if it is an empty string; may
be given multiple times
--number, --int, --float, -i, -f YAMLPATH:str
Cast each node matching the given YAML Path
query as a number; may be given multiple
times
--schema, -s NESTEDTEXTFILE:ExistingFile
Cast nodes matching YAML Path queries
specified in a NestedText document. It must
be a map with one or more of the keys:
'null', 'boolean', 'number'Each key's value
is a list of YAML Paths.; may be given
multiple times
```
</details>
<details>
<summary>nt2yaml</summary>
```
nt2yaml 0.2.7
Read NestedText and output its content as YAML.
By default, generated YAML values will only contain strings, arrays, and maps,
but you can cast nodes matching YAML Paths to boolean, null, number, or date.
Casting switches may be before or after file arguments.
Examples:
nt2yaml example.nt
nt2yaml <example.nt
cat example.nt | nt2yaml
nt2yaml --int People.age --boolean 'People."is a wizard"' example.nt
Usage:
nt2yaml [SWITCHES] input_files...
Meta-switches:
-h, --help Prints this help message and quits
-v, --version Prints the program's version and quits
Switches:
--boolean, -b YAMLPATH:str Cast each node matching the given YAML Path
query as boolean; may be given multiple
times
--date, -d YAMLPATH:str Cast each node matching the given YAML Path
query as a date, assuming it's ISO 8601; may
be given multiple times
--null, -n YAMLPATH:str Cast each node matching the given YAML Path
query as null, if it is an empty string; may
be given multiple times
--number, --int, --float, -i, -f YAMLPATH:str
Cast each node matching the given YAML Path
query as a number; may be given multiple
times
--schema, -s NESTEDTEXTFILE:ExistingFile
Cast nodes matching YAML Path queries
specified in a NestedText document. It must
be a map with one or more of the keys:
'null', 'boolean', 'number'Each key's value
is a list of YAML Paths.; may be given
multiple times
```
</details>
<details>
<summary>nt2toml</summary>
```
nt2toml 0.2.7
Read NestedText and output its content as TOML.
By default, generated TOML values will only contain strings, arrays, and maps,
but you can cast nodes matching YAML Paths to boolean, number, or date.
Casting switches may be before or after file arguments.
Examples:
nt2toml example.nt
nt2toml <example.nt
cat example.nt | nt2toml
nt2toml --int People.age --boolean 'People."is a wizard"' example.nt
Usage:
nt2toml [SWITCHES] input_files...
Meta-switches:
-h, --help Prints this help message and quits
-v, --version Prints the program's version and quits
Switches:
--boolean, -b YAMLPATH:str Cast each node matching the given YAML Path
query as boolean; may be given multiple
times
--date, -d YAMLPATH:str Cast each node matching the given YAML Path
query as a date, assuming it's ISO 8601; may
be given multiple times
--number, --int, --float, -i, -f YAMLPATH:str
Cast each node matching the given YAML Path
query as a number; may be given multiple
times
--schema, -s NESTEDTEXTFILE:ExistingFile
Cast nodes matching YAML Path queries
specified in a NestedText document. It must
be a map with one or more of the keys:
'null', 'boolean', 'number'Each key's value
is a list of YAML Paths.; may be given
multiple times
```
</details>
<details>
<summary>json2nt</summary>
```
json2nt 0.2.7
Read JSON and output its content as NestedText.
Examples:
json2nt example.json
json2nt <example.json
cat example.json | json2nt
Usage:
json2nt [SWITCHES] input_files...
Meta-switches:
-h, --help Prints this help message and quits
-v, --version Prints the program's version and quits
Switches:
--to-schema, -s Rather than convert the inputs, generate a schema
```
</details>
<details>
<summary>yaml2nt</summary>
```
yaml2nt 0.2.7
Read YAML and output its content as NestedText.
Examples:
yaml2nt example.yml
yaml2nt <example.yml
cat example.yml | yaml2nt
Usage:
yaml2nt [SWITCHES] input_files...
Meta-switches:
-h, --help Prints this help message and quits
-v, --version Prints the program's version and quits
Switches:
--to-schema, -s Rather than convert the inputs, generate a schema
```
</details>
<details>
<summary>toml2nt</summary>
```
toml2nt 0.2.7
Read TOML and output its content as NestedText.
Examples:
toml2nt example.yml
toml2nt <example.yml
cat example.yml | toml2nt
Usage:
toml2nt [SWITCHES] input_files...
Meta-switches:
-h, --help Prints this help message and quits
-v, --version Prints the program's version and quits
Switches:
--to-schema, -s Rather than convert the inputs, generate a schema
```
</details>
#### Limitations
##### Non-string Keys
YAML officially supports non-string key types,
like maps, lists, and numbers.
Support for non-string keys varies from one YAML parser to the next,
and is currently not handled by NestedTextTo.
If anyone is interested in using NestedTextTo with non-string key types,
please open an issue and I'll see what I can do!
### More Examples
#### View JSON Lines logs in a more readable format
```console
$ cat log.jsonl
```
<details>
<summary>Output</summary>
```json
{"chat_id": 651321, "event": "receiving code", "user_first_name": "Andy", "user_id": 651321}
{"event": "guessed syntax", "ext": null, "probability": 0.05201493203639984, "probability_min": 0.12, "syntax": "Matlab"}
{"chat_id": 651321, "event": "colorizing code", "syntax": "py3", "user_first_name": "Andy", "user_id": 651321}
{"event": "Got deletion request", "reply_to_msg_user_id": 651321, "user_id": 651321}
{"chat_id": 651321, "event": "failed to delete message (it's probably gone already)", "exception": "Traceback (most recent call last):\n File \"/home/andy/Code/colorcodebot/app/colorcodebot.py\", line 278, in delete_after_delay\n bot.delete_message(message.chat.id, message.message_id)\n File \"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/__init__.py\", line 1081, in delete_message\n return apihelper.delete_message(self.token, chat_id, message_id, timeout)\n File \"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\", line 1299, in delete_message\n return _make_request(token, method_url, params=payload, method='post')\n File \"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\", line 152, in _make_request\n json_result = _check_result(method_name, result)\n File \"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\", line 179, in _check_result\n raise ApiTelegramException(method_name, result, result_json)\ntelebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: message to delete not found"}
```
</details>
```console
$ json2nt log.jsonl
```
<details>
<summary>Output</summary>
```yaml
-
chat_id: 651321
event: receiving code
user_first_name: Andy
user_id: 651321
-
event: guessed syntax
ext:
probability: 0.05201493203639984
probability_min: 0.12
syntax: Matlab
-
chat_id: 651321
event: colorizing code
syntax: py3
user_first_name: Andy
user_id: 651321
-
event: Got deletion request
reply_to_msg_user_id: 651321
user_id: 651321
-
chat_id: 651321
event: failed to delete message (it's probably gone already)
exception:
> Traceback (most recent call last):
> File "/home/andy/Code/colorcodebot/app/colorcodebot.py", line 278, in delete_after_delay
> bot.delete_message(message.chat.id, message.message_id)
> File "/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/__init__.py", line 1081, in delete_message
> return apihelper.delete_message(self.token, chat_id, message_id, timeout)
> File "/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py", line 1299, in delete_message
> return _make_request(token, method_url, params=payload, method='post')
> File "/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py", line 152, in _make_request
> json_result = _check_result(method_name, result)
> File "/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py", line 179, in _check_result
> raise ApiTelegramException(method_name, result, result_json)
> telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: message to delete not found
```
</details>
#### View TOML as NestedText
![View TOML as NestedText](https://user-images.githubusercontent.com/1787385/199562999-d702bfb5-859c-417d-b8a4-ffb0d36e7537.png)
#### Convert NestedText to TOML, with and without casting
![Convert NestedText to TOML, with and without casting](https://user-images.githubusercontent.com/1787385/199562703-db0fec70-bb18-431a-aa01-c4858b449c56.png)
#### Convert NestedText to TOML with casting via auto-schema
![Convert NestedText to TOML with casting via auto-schema](https://user-images.githubusercontent.com/1787385/199562909-a1060b9b-0446-4aba-81b1-5ff288c839ed.png)
#### Query TOML with JSON tools, with and without casting
![Query TOML with JSON tools, with and without casting](https://user-images.githubusercontent.com/1787385/199562454-b6267df2-aaa9-421b-a47d-93cb49641a30.png)
### Development Docs
For local development, it's recommended to activate a venv, then
```console
$ pip install -r local-requirements.txt
```
From there, you may want to look at common task definitions:
```console
$ task -l
$ nox -l
```
And you may wish to browse the structure and in-code documentation as rendered HTML,
at [the GitHub Pages site](https://andydecleyre.github.io/nestedtextto/moduleIndex.html).
Raw data
{
"_id": null,
"home_page": null,
"name": "nt2",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "NestedText, JSON, YAML, TOML",
"author": "Andy Kluger",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/7c/a1/cf019ac104eb99ed786ebbf54a94a7587f5de95c4ca5e423293595fe8428/nt2-0.2.7.tar.gz",
"platform": null,
"description": "# NestedTextTo\n## CLI to convert between NestedText and JSON, YAML or TOML, with explicit type casting\n\n![Python versions](https://img.shields.io/pypi/pyversions/nt2?logo=python)\n[![PyPI version](https://img.shields.io/pypi/v/nt2?logo=pypi&label=PyPI&color=yellowgreen)](https://pypi.org/project/nt2/)\n[![Publish to PyPI](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/pypi.yml?label=Publish%20to%20PyPI&logo=github)](https://github.com/AndydeCleyre/nestedtextto/actions/workflows/pypi.yml)\n\n![Runs on Linux](https://img.shields.io/badge/Runs%20on-Linux-yellowgreen?logo=linux)\n![Runs on macOS](https://img.shields.io/badge/Runs%20on-macOS-red?logo=macos)\n![Runs on Windows](https://img.shields.io/badge/Runs%20on-Windows-blue?logo=windows)\n\n[![Tests badge](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/test.yml?branch=develop&label=Tests&logo=github)](https://github.com/AndydeCleyre/nestedtextto/actions/workflows/test.yml)\n[![codecov badge](https://codecov.io/github/AndydeCleyre/nestedtextto/branch/develop/graph/badge.svg?token=M30UZQVM4Q)](https://codecov.io/github/AndydeCleyre/nestedtextto)\n\n\n[![Format and lint](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/fmt.yml?branch=develop&label=Format%20%26%20Lint&logo=github)](https://github.com/AndydeCleyre/nestedtextto/actions/workflows/fmt.yml)\n[![Generate docs from templates](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/doc.yml?branch=develop&label=Make%20Docs&logo=github)](https://andydecleyre.github.io/nestedtextto/moduleIndex.html)\n[![Requirements badge](https://img.shields.io/github/actions/workflow/status/andydecleyre/nestedtextto/reqs.yml?branch=develop&label=Bump%20Reqs&logo=github)](https://github.com/AndydeCleyre/nestedtextto/actions/workflows/reqs.yml)\n\n<img src=\"https://github.com/AndydeCleyre/nestedtextto/blob/assets/logo.png?raw=true\" alt=\"logo\" width=\"160\" height=\"160\" />\n\nThis project was created in appreciation for the design of [NestedText](https://nestedtext.org/),\nthe readability of [yamlpath](https://github.com/wwkimball/yamlpath) queries,\nthe utility of [cattrs](https://cattrs.readthedocs.io/),\nand the joy of [plumbum](https://plumbum.readthedocs.io/)\nand [ward](https://ward.readthedocs.io/) --\nnone of which are this author's projects.\n\nThis project, NestedTextTo, provides six command line tools\nfor convenient conversion between NestedText and other formats:\n- `nt2json`, `nt2toml`, `nt2yaml`\n- `json2nt`, `toml2nt`, `yaml2nt`\n\n---\n\n<!--TOC-->\n\n- [What's NestedText?](#whats-nestedtext)\n- [How does this translate to formats with more value types?](#how-does-this-translate-to-formats-with-more-value-types)\n- [Installation](#installation)\n - [Shell Completion](#shell-completion)\n- [Usage Docs](#usage-docs)\n - [Limitations](#limitations)\n- [More Examples](#more-examples)\n - [View JSON Lines logs in a more readable format](#view-json-lines-logs-in-a-more-readable-format)\n - [View TOML as NestedText](#view-toml-as-nestedtext)\n - [Convert NestedText to TOML, with and without casting](#convert-nestedtext-to-toml-with-and-without-casting)\n - [Convert NestedText to TOML with casting via auto-schema](#convert-nestedtext-to-toml-with-casting-via-auto-schema)\n - [Query TOML with JSON tools, with and without casting](#query-toml-with-json-tools-with-and-without-casting)\n- [Development Docs](#development-docs)\n\n<!--TOC-->\n\n---\n\n### What's NestedText?\n\nFrom the NestedText docs, with emphasis added:\n\n> 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.\n\n### How does this translate to formats with more value types?\n\nWhen converting from NestedText to formats supporting more value types,\nall plain values will be strings by default.\nBut you can provide options to cast any values as numbers, booleans, nulls, or dates/times,\nif the target format supports it, using the powerful and concise YAML Path query syntax.\n\n```console\n$ cat example.nt\n```\n```yaml\npeople:\n -\n name: Bill Sky\n problems: 99\n happy: False\n -\n name: Vorbis Florbis\n problems: 6\n happy: yes\n```\n```console\n$ nt2json example.nt --number /people/problems --boolean /people/happy\n```\n```json\n{\n \"people\": [\n {\n \"name\": \"Bill Sky\",\n \"problems\": 99,\n \"happy\": false\n },\n {\n \"name\": \"Vorbis Florbis\",\n \"problems\": 6,\n \"happy\": true\n }\n ]\n}\n```\n\nYou may instead store these type mappings in a NestedText \"schema\" file.\n\n```console\n$ cat example.types.nt\n```\n```yaml\nboolean:\n - /people/happy\nnumber:\n - /people/problems\n```\n\nThe following command will then also yield the above JSON:\n\n```console\n$ nt2json example.nt --schema example.types.nt\n```\n\nSuch a schema may be automatically generated from JSON/TOML/YAML:\n\n```console\n$ json2nt --to-schema example.json\n```\n\nOptions may be provided before or after the document,\nand content may be piped directly to the command instead of specifying a file.\n\nFor more YAML Path syntax information see\n[the YAML Path wiki](https://github.com/wwkimball/yamlpath/wiki/Search-Expressions).\n\nFor example, you could match all items which are *probably* intended as booleans,\nat any depth, with `--boolean '/**[.=~/^(?i)(yes|no|true|false)$/]'`.\n\n### Installation\n\nIf you don't need TOML support, you can omit the `[toml]` bits below.\n\nHere are some ways to install it:\n\n```console\n$ uv tool install 'nt2[toml]' # Install using uv (Python all-around manager)\n$ pipx install 'nt2[toml]' # Install using pipx (Python app manager)\n$ pipz install 'nt2[toml]' # Install using zpy (Python app and environment manager for Zsh)\n$ pip install --user 'nt2[toml]' # Install in your user's environment\n$ pip install 'nt2[toml]' # Install in current environment\n```\n\nI recommend using [uv](https://github.com/astral-sh/uv),\n[pipx](https://github.com/pypa/pipx),\nor `pipz` from [zpy](https://github.com/AndydeCleyre/zpy).\n\n#### Shell Completion\n\nFor Zsh completion, add this line to your `.zshrc`, any time after `compinit`:\n\n```zsh\nif (( $+functions[compdef] )) && (( $+commands[nt2json] )) compdef _gnu_generic nt2yaml nt2toml nt2json json2nt toml2nt yaml2nt\n```\n\n### Usage Docs\n\n<details>\n <summary>nt2json</summary>\n\n```\nnt2json 0.2.7\n\nRead NestedText and output its content as JSON.\n\nBy default, generated JSON values will only contain strings, arrays, and maps,\nbut you can cast nodes matching YAML Paths to boolean, null, or number.\n\nCasting switches may be before or after file arguments.\n\nExamples:\n nt2json example.nt\n nt2json <example.nt\n cat example.nt | nt2json\n nt2json --int People.age --boolean 'People.\"is a wizard\"' example.nt\n\nUsage:\n nt2json [SWITCHES] input_files...\n\nMeta-switches:\n -h, --help Prints this help message and quits\n -v, --version Prints the program's version and quits\n\nSwitches:\n --boolean, -b YAMLPATH:str Cast each node matching the given YAML Path\n query as boolean; may be given multiple\n times\n --null, -n YAMLPATH:str Cast each node matching the given YAML Path\n query as null, if it is an empty string; may\n be given multiple times\n --number, --int, --float, -i, -f YAMLPATH:str\n Cast each node matching the given YAML Path\n query as a number; may be given multiple\n times\n --schema, -s NESTEDTEXTFILE:ExistingFile\n Cast nodes matching YAML Path queries\n specified in a NestedText document. It must\n be a map with one or more of the keys:\n 'null', 'boolean', 'number'Each key's value\n is a list of YAML Paths.; may be given\n multiple times\n\n\n```\n\n</details>\n\n\n<details>\n <summary>nt2yaml</summary>\n\n```\nnt2yaml 0.2.7\n\nRead NestedText and output its content as YAML.\n\nBy default, generated YAML values will only contain strings, arrays, and maps,\nbut you can cast nodes matching YAML Paths to boolean, null, number, or date.\n\nCasting switches may be before or after file arguments.\n\nExamples:\n nt2yaml example.nt\n nt2yaml <example.nt\n cat example.nt | nt2yaml\n nt2yaml --int People.age --boolean 'People.\"is a wizard\"' example.nt\n\nUsage:\n nt2yaml [SWITCHES] input_files...\n\nMeta-switches:\n -h, --help Prints this help message and quits\n -v, --version Prints the program's version and quits\n\nSwitches:\n --boolean, -b YAMLPATH:str Cast each node matching the given YAML Path\n query as boolean; may be given multiple\n times\n --date, -d YAMLPATH:str Cast each node matching the given YAML Path\n query as a date, assuming it's ISO 8601; may\n be given multiple times\n --null, -n YAMLPATH:str Cast each node matching the given YAML Path\n query as null, if it is an empty string; may\n be given multiple times\n --number, --int, --float, -i, -f YAMLPATH:str\n Cast each node matching the given YAML Path\n query as a number; may be given multiple\n times\n --schema, -s NESTEDTEXTFILE:ExistingFile\n Cast nodes matching YAML Path queries\n specified in a NestedText document. It must\n be a map with one or more of the keys:\n 'null', 'boolean', 'number'Each key's value\n is a list of YAML Paths.; may be given\n multiple times\n\n\n```\n\n</details>\n\n\n<details>\n <summary>nt2toml</summary>\n\n```\nnt2toml 0.2.7\n\nRead NestedText and output its content as TOML.\n\nBy default, generated TOML values will only contain strings, arrays, and maps,\nbut you can cast nodes matching YAML Paths to boolean, number, or date.\n\nCasting switches may be before or after file arguments.\n\nExamples:\n nt2toml example.nt\n nt2toml <example.nt\n cat example.nt | nt2toml\n nt2toml --int People.age --boolean 'People.\"is a wizard\"' example.nt\n\nUsage:\n nt2toml [SWITCHES] input_files...\n\nMeta-switches:\n -h, --help Prints this help message and quits\n -v, --version Prints the program's version and quits\n\nSwitches:\n --boolean, -b YAMLPATH:str Cast each node matching the given YAML Path\n query as boolean; may be given multiple\n times\n --date, -d YAMLPATH:str Cast each node matching the given YAML Path\n query as a date, assuming it's ISO 8601; may\n be given multiple times\n --number, --int, --float, -i, -f YAMLPATH:str\n Cast each node matching the given YAML Path\n query as a number; may be given multiple\n times\n --schema, -s NESTEDTEXTFILE:ExistingFile\n Cast nodes matching YAML Path queries\n specified in a NestedText document. It must\n be a map with one or more of the keys:\n 'null', 'boolean', 'number'Each key's value\n is a list of YAML Paths.; may be given\n multiple times\n\n\n```\n\n</details>\n\n\n<details>\n <summary>json2nt</summary>\n\n```\njson2nt 0.2.7\n\nRead JSON and output its content as NestedText.\n\nExamples:\n json2nt example.json\n json2nt <example.json\n cat example.json | json2nt\n\nUsage:\n json2nt [SWITCHES] input_files...\n\nMeta-switches:\n -h, --help Prints this help message and quits\n -v, --version Prints the program's version and quits\n\nSwitches:\n --to-schema, -s Rather than convert the inputs, generate a schema\n\n\n```\n\n</details>\n\n\n<details>\n <summary>yaml2nt</summary>\n\n```\nyaml2nt 0.2.7\n\nRead YAML and output its content as NestedText.\n\nExamples:\n yaml2nt example.yml\n yaml2nt <example.yml\n cat example.yml | yaml2nt\n\nUsage:\n yaml2nt [SWITCHES] input_files...\n\nMeta-switches:\n -h, --help Prints this help message and quits\n -v, --version Prints the program's version and quits\n\nSwitches:\n --to-schema, -s Rather than convert the inputs, generate a schema\n\n\n```\n\n</details>\n\n\n<details>\n <summary>toml2nt</summary>\n\n```\ntoml2nt 0.2.7\n\nRead TOML and output its content as NestedText.\n\nExamples:\n toml2nt example.yml\n toml2nt <example.yml\n cat example.yml | toml2nt\n\nUsage:\n toml2nt [SWITCHES] input_files...\n\nMeta-switches:\n -h, --help Prints this help message and quits\n -v, --version Prints the program's version and quits\n\nSwitches:\n --to-schema, -s Rather than convert the inputs, generate a schema\n\n\n```\n\n</details>\n\n\n#### Limitations\n\n##### Non-string Keys\n\nYAML officially supports non-string key types,\nlike maps, lists, and numbers.\nSupport for non-string keys varies from one YAML parser to the next,\nand is currently not handled by NestedTextTo.\n\nIf anyone is interested in using NestedTextTo with non-string key types,\nplease open an issue and I'll see what I can do!\n\n### More Examples\n\n#### View JSON Lines logs in a more readable format\n\n```console\n$ cat log.jsonl\n```\n<details>\n <summary>Output</summary>\n\n```json\n{\"chat_id\": 651321, \"event\": \"receiving code\", \"user_first_name\": \"Andy\", \"user_id\": 651321}\n{\"event\": \"guessed syntax\", \"ext\": null, \"probability\": 0.05201493203639984, \"probability_min\": 0.12, \"syntax\": \"Matlab\"}\n{\"chat_id\": 651321, \"event\": \"colorizing code\", \"syntax\": \"py3\", \"user_first_name\": \"Andy\", \"user_id\": 651321}\n{\"event\": \"Got deletion request\", \"reply_to_msg_user_id\": 651321, \"user_id\": 651321}\n{\"chat_id\": 651321, \"event\": \"failed to delete message (it's probably gone already)\", \"exception\": \"Traceback (most recent call last):\\n File \\\"/home/andy/Code/colorcodebot/app/colorcodebot.py\\\", line 278, in delete_after_delay\\n bot.delete_message(message.chat.id, message.message_id)\\n File \\\"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/__init__.py\\\", line 1081, in delete_message\\n return apihelper.delete_message(self.token, chat_id, message_id, timeout)\\n File \\\"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\\\", line 1299, in delete_message\\n return _make_request(token, method_url, params=payload, method='post')\\n File \\\"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\\\", line 152, in _make_request\\n json_result = _check_result(method_name, result)\\n File \\\"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\\\", line 179, in _check_result\\n raise ApiTelegramException(method_name, result, result_json)\\ntelebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: message to delete not found\"}\n```\n\n</details>\n\n```console\n$ json2nt log.jsonl\n```\n\n<details>\n <summary>Output</summary>\n\n```yaml\n-\n chat_id: 651321\n event: receiving code\n user_first_name: Andy\n user_id: 651321\n-\n event: guessed syntax\n ext:\n probability: 0.05201493203639984\n probability_min: 0.12\n syntax: Matlab\n-\n chat_id: 651321\n event: colorizing code\n syntax: py3\n user_first_name: Andy\n user_id: 651321\n-\n event: Got deletion request\n reply_to_msg_user_id: 651321\n user_id: 651321\n-\n chat_id: 651321\n event: failed to delete message (it's probably gone already)\n exception:\n > Traceback (most recent call last):\n > File \"/home/andy/Code/colorcodebot/app/colorcodebot.py\", line 278, in delete_after_delay\n > bot.delete_message(message.chat.id, message.message_id)\n > File \"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/__init__.py\", line 1081, in delete_message\n > return apihelper.delete_message(self.token, chat_id, message_id, timeout)\n > File \"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\", line 1299, in delete_message\n > return _make_request(token, method_url, params=payload, method='post')\n > File \"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\", line 152, in _make_request\n > json_result = _check_result(method_name, result)\n > File \"/home/andy/.local/share/venvs/84f7fb558856f9ccc2c54e3d122862b6/venv/lib/python3.10/site-packages/telebot/apihelper.py\", line 179, in _check_result\n > raise ApiTelegramException(method_name, result, result_json)\n > telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: message to delete not found\n```\n\n</details>\n\n#### View TOML as NestedText\n\n![View TOML as NestedText](https://user-images.githubusercontent.com/1787385/199562999-d702bfb5-859c-417d-b8a4-ffb0d36e7537.png)\n\n#### Convert NestedText to TOML, with and without casting\n\n![Convert NestedText to TOML, with and without casting](https://user-images.githubusercontent.com/1787385/199562703-db0fec70-bb18-431a-aa01-c4858b449c56.png)\n\n#### Convert NestedText to TOML with casting via auto-schema\n\n![Convert NestedText to TOML with casting via auto-schema](https://user-images.githubusercontent.com/1787385/199562909-a1060b9b-0446-4aba-81b1-5ff288c839ed.png)\n\n#### Query TOML with JSON tools, with and without casting\n\n![Query TOML with JSON tools, with and without casting](https://user-images.githubusercontent.com/1787385/199562454-b6267df2-aaa9-421b-a47d-93cb49641a30.png)\n\n### Development Docs\n\nFor local development, it's recommended to activate a venv, then\n\n```console\n$ pip install -r local-requirements.txt\n```\n\nFrom there, you may want to look at common task definitions:\n\n```console\n$ task -l\n$ nox -l\n```\n\nAnd you may wish to browse the structure and in-code documentation as rendered HTML,\nat [the GitHub Pages site](https://andydecleyre.github.io/nestedtextto/moduleIndex.html).\n",
"bugtrack_url": null,
"license": null,
"summary": "CLI to convert between NestedText and JSON, YAML or TOML, with explicit type casting.",
"version": "0.2.7",
"project_urls": {
"Home": "https://github.com/andydecleyre/nestedtextto"
},
"split_keywords": [
"nestedtext",
" json",
" yaml",
" toml"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "95c345e82cd5dd5f8d711407b9e0551e0dc619bc3dcc97a254052301f9dd658c",
"md5": "8375d5a516ea90bb9e995368d6d347fc",
"sha256": "f1ace151f13e9267c9a09a4ad3cb16634265b9e4f733e91ad536dca4a5a7da79"
},
"downloads": -1,
"filename": "nt2-0.2.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8375d5a516ea90bb9e995368d6d347fc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 19336,
"upload_time": "2024-10-15T20:07:17",
"upload_time_iso_8601": "2024-10-15T20:07:17.578099Z",
"url": "https://files.pythonhosted.org/packages/95/c3/45e82cd5dd5f8d711407b9e0551e0dc619bc3dcc97a254052301f9dd658c/nt2-0.2.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "7ca1cf019ac104eb99ed786ebbf54a94a7587f5de95c4ca5e423293595fe8428",
"md5": "6086b1bdfa57c1a15b73ea467948760b",
"sha256": "d394fdf82f1b21c30bd31bbaa13c42d1122e42473fdb76800b7dc1d883a5dac8"
},
"downloads": -1,
"filename": "nt2-0.2.7.tar.gz",
"has_sig": false,
"md5_digest": "6086b1bdfa57c1a15b73ea467948760b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 38256,
"upload_time": "2024-10-15T20:07:19",
"upload_time_iso_8601": "2024-10-15T20:07:19.815362Z",
"url": "https://files.pythonhosted.org/packages/7c/a1/cf019ac104eb99ed786ebbf54a94a7587f5de95c4ca5e423293595fe8428/nt2-0.2.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-15 20:07:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "andydecleyre",
"github_project": "nestedtextto",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nt2"
}