convfmt is a command line tool in rust which can convert between formats:
$ convfmt --help
cli tool which can convert different formats
Usage: convfmt [OPTIONS] --from <FROM> --to <TO>
Options:
-f, --from <FROM> [possible values: bson, csv, dotenv, hjson, hocon, json, json5, jsonl, plist, ron, toml, toon, xml, yaml]
-t, --to <TO> [possible values: bson, csv, dotenv, hjson, hocon, json, json5, jsonl, plist, ron, toml, toon, xml, yaml]
-c, --compact Compress output if possible (default = false)
-s, --sort-keys Sort keys of objects (default = false)
-i, --ignore-unsupported Drop values the target format can't represent, e.g. `null` for toml (default = false)
-h, --help Print help
-V, --version Print version
$ cat cfg.yml | convfmt -f yaml -t toml > cfg.toml
$ convfmt -f json -t json < compact.json > pretty.json
$ convfmt -f json -t json --sort-keys < unordered.json > sorted.json
$ convfmt -f json -t toml --ignore-unsupported < with-nulls.json > cfg.toml
$ curl https://api.github.com/users/oriontvv | convfmt -f json -t json5 > api.json5
By default convfmt tries to use pretty format. Enable --compact option for compression.
By default the original order of keys is preserved. Enable --sort-keys option to sort keys of all objects (recursively) in alphabetical order.
Beware of nulls, some formats don't support them: toml fails to serialize a null and plist silently turns it into an empty string. Enable --ignore-unsupported option to drop such values.
There are few ways:
-
Use the web version without installing anything, convert locally in your browser
-
Macos homebrew tap
brew install oriontvv/tap/convfmt
-
Download latest binary
-
Run it from docker without installing anything (
-iis required,convfmtreads stdin)
$ cat cfg.yml | docker run --rm -i oriontvv/convfmt -f yaml -t toml > cfg.toml
- Run or install it with nix (flakes required)
nix run github:oriontvv/convfmt -- -f yaml -t toml < cfg.yml
nix profile install github:oriontvv/convfmt
- Install binary using cargo-binstall
cargo install cargo-binstall && cargo binstall convfmt
cargo install --git https://github.com/oriontvv/convfmt