https://github.com/giladbarnea/to
A simple CLI tool to convert and diff between JSON, YAML, TOML, JSON5 and Python collections.
https://github.com/giladbarnea/to
conversion data data-conversion json json5 parser script terminal toml yaml
Last synced: 10 months ago
JSON representation
A simple CLI tool to convert and diff between JSON, YAML, TOML, JSON5 and Python collections.
- Host: GitHub
- URL: https://github.com/giladbarnea/to
- Owner: giladbarnea
- License: mit
- Created: 2024-07-29T08:54:48.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-04T14:53:31.000Z (about 1 year ago)
- Last Synced: 2025-04-11T21:53:01.900Z (10 months ago)
- Topics: conversion, data, data-conversion, json, json5, parser, script, terminal, toml, yaml
- Language: Python
- Homepage:
- Size: 115 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# to
CLI & Python package to convert or diff between JSON, YAML, TOML, JSON5 and literal Python collections.
## Examples
Given a json file `example.json`:
```json
{
"The Great Gatsby": {
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"year": 1925,
"null_example": null,
"recommended": true,
"genres": ["Novel", "Fiction"]
}
}
```
### `to convert -f yaml`
$ to.py convert example.json -f yaml

### `--clean` `--pretty` options
$ to.py convert example.json -f toml --clean --pretty
The `--clean` flag removes the `null_example` key with a `null` value.
The `--pretty` flag formats the output and prints it with syntax highlighting with `rich`.

## Usage
### to.py
```
usage: to.py [-h] {convert,diff} ...
Convert or diff between JSON, YAML, TOML, JSON5 and literal Python collections.
positional arguments:
{convert,diff}
convert Convert between different formats.
diff Convert two files or data to FORMAT, then diff the result.
options:
-h, --help show this help message and exit
```
———————
#### `to convert`
```
usage: to.py convert [-h] -f {json,json5,toml,yaml} [-o OUTPUT] [--width WIDTH] [--sort-keys] [--clean] [-p] [input]
positional arguments:
input Input string, file path, '-' for stdin. Can be omitted if piping data into the script (default: -)
options:
-h, --help show this help message and exit
-f {json,json5,toml,yaml}, --format {json,json5,toml,yaml}
Output format (default: None)
-o OUTPUT, --output OUTPUT
Output file path or 'stdout' for standard output (default) (default: stdout)
--width WIDTH Width for yaml output (default: 120) (default: 120)
--sort-keys Sort keys in the output (default: True) (default: True)
--clean Clean the output before writing (default: False)
-p, --pretty Pretty print the output (default: False)
```
———————
#### `to diff`
```
usage: to.py diff [-h] [-o OUTPUT_OR_TOOL] -f {json,json5,toml,yaml} [-q] [--ignore-order] [--ignore-empty] [--ignore-space] input1 input2
positional arguments:
input1 Input string, file path, '-' for stdin.
input2 Input string, file path, '-' for stdin.
options:
-h, --help show this help message and exit
-o OUTPUT_OR_TOOL, --output OUTPUT_OR_TOOL
Choices: an output file path, or diff, delta, code, pycharm. If an output file path: write the output of coreutils 'diff' to this path. 'diff': print the output of coreutils' diff to
stdout (default). A diff program — 'delta', 'code' or 'pycharm': view the diff with the respective tool. (default: diff)
-f {json,json5,toml,yaml}, --format {json,json5,toml,yaml}
Convert inputs to this format before diffing. (default: None)
-q, --quiet Do not print the diff to stdout, only return 0 for no difference, 1 for difference. (default: False)
--ignore-order Ignore order of keys when diffing. (default: False)
--ignore-empty Do not count a missing key as different from an empty value. (default: False)
--ignore-space Ignore differences in whitespace. (default: False)
```