#json #yaml #jq #hcl

bin+lib dts

A tool to deserialize, transform and serialize data between different encodings

14 unstable releases (3 breaking)

Uses new Rust 2021

0.4.2 Jul 13, 2022
0.4.1 Jul 3, 2022
0.4.0 Jun 26, 2022
0.3.1 Jun 17, 2022
0.1.0 Mar 4, 2022

#397 in Encoding

Download history 3/week @ 2022-06-10 48/week @ 2022-06-17 42/week @ 2022-06-24 48/week @ 2022-07-01 30/week @ 2022-07-08 44/week @ 2022-07-15 45/week @ 2022-07-22 14/week @ 2022-07-29 16/week @ 2022-08-05 6/week @ 2022-08-12 15/week @ 2022-08-19 16/week @ 2022-08-26 42/week @ 2022-09-09 15/week @ 2022-09-16 5/week @ 2022-09-23

62 downloads per month

MIT and maybe LGPL-3.0-or-later

115KB
2.5K SLoC

dts

Build Status MIT License

A simple tool to deserialize data from an input encoding, transform it and serialize it back into an output encoding.

Uses jq for data transformation and requires rust >= 1.56.0.

Installation

Check out the releases page for prebuilt versions of dts.

Statically-linked binaries are also available: look for archives with musl in the filename.

From crates.io

cargo install dts

From source

Clone the repository and run:

cargo install --locked --path .

Usage

dts [<source>...] [-j <jq-expression>] [-O <sink>...]

For a full list of available flags consult the help:

dts --help

Examples

Convert YAML to TOML:

dts input.yaml -o toml

Load all YAML files from sub directories and merge them into one:

dts . --glob '**/*.yaml' output.yaml

Transform the input data using a jq expression:

dts tests/fixtures/example.json -j '.users | map(select(.age < 30))'

Use jq filter expression from a file:

dts tests/fixtures/example.json -j @my-filter.jq

Read data from stdin:

echo '{"foo": {"bar": "baz"}}' | dts -i json -o yaml

Output colors and themes

dts supports output coloring and syntax highlighting. The coloring behaviour can be controlled via the --color flag or DTS_COLOR environment variable.

If the default theme used for syntax highlighting does not suit you, you can change it via the --theme flag or DTS_THEME environment variable.

Available themes can be listed via:

dts --list-themes

Hint: The color feature can be disabled at compile time if you don't want to have colors at all. See the feature flags section below.

Supported Encodings

Right now dts supports the following encodings:

  • JSON
  • YAML
  • TOML
  • JSON5 (deserialize only)
  • CSV
  • QueryString
  • XML
  • Text
  • Gron
  • HCL (deserialize, serialize only supports HCL attributes)

Feature flags

To build dts without its default features enabled, run:

cargo build --no-default-features --release

The following feature flags are available:

  • color: Enables support for colored output. This feature is enabled by default.

    If you just want to disable colors by default with the option to enable them conditionally, you can also set the NO_COLOR environment variable or set DTS_COLOR=never.

  • jaq: Use jaq-core to process transformation filters instead of shelling out to jq.

    This feature is experimental and not enabled by default yet.

License

The source code of dts is released under the MIT License. See the bundled LICENSE file for details.

Dependencies

~11–15MB
~318K SLoC