#cli #json #yaml

app yj

Command line tool that converts YAML to JSON

19 releases (9 stable)

new 1.2.2 Jul 1, 2022
1.2.0 Jan 3, 2022
1.1.35 Dec 10, 2021
1.1.34 Oct 31, 2021
0.6.0 Dec 19, 2018

#102 in Command line utilities

Download history 53/week @ 2022-03-10 79/week @ 2022-03-17 3/week @ 2022-03-24 4/week @ 2022-03-31 5/week @ 2022-04-07 7/week @ 2022-04-14 5/week @ 2022-04-21 70/week @ 2022-04-28 243/week @ 2022-05-05 294/week @ 2022-05-12 84/week @ 2022-05-19 77/week @ 2022-05-26 208/week @ 2022-06-02 3/week @ 2022-06-09 3/week @ 2022-06-16 9/week @ 2022-06-23

224 downloads per month

Apache-2.0

14KB
157 lines

YJ - YAML to JSON

Build Status

Simple command line tool to convert a YAML input file into a JSON output file.

How to, etc.

Built in help

$ yj --help
yj 1.2.2

Command line tool that converts YAML to JSON

USAGE:
    yj [FLAGS] [OPTIONS] [INPUT]

ARGS:
    <INPUT>    Input YAML file name. Defaults to stdin

FLAGS:
    -c, --compact    Use compact formatting for the JSON output
    -h, --help       Print help information
    -j, --json       Parse the input as JSON. For most use cases, this option
                     makes no difference. Valid JSON is valid YAML, so JSON
                     input will (should?) parse correctly even when being
                     handled with the YAML parser. Use this option when you
                     want failure (instead of weird results) when the input is
                     invalid JSON
    -V, --version    Print version information
    -y, --yaml       Format the output as YAML instead of JSON

OPTIONS:
    -o, --output <OUTPUT>    Output file name for the JSON. Defaults to stdout

Installing

Local build and install with cargo:

$ cargo install yj

Prebuilt binaries are available on Github releases for some common platforms.

On macOS, the prebuilt binary can be installed using Homebrew. Unfortunately, Homebrew picked up a different utility with the name yj after I chose that name here. So, a simple brew install yj gets that tool, not this one 😞.

$ brew tap bruceadams/utilities
$ brew install bruceadams/utilities/yj

Alternatively on macOS, you may also install yj using MacPorts:

$ sudo port selfupdate
$ sudo port install yj

Minimal Docker images are available on Docker Hub:

$ docker pull bruceadams/yj

Example runs

$ cat .travis.yml
language: rust
os:
  - linux
  - osx
  - windows
rust:
  - stable
  - beta
  - nightly
matrix:
  allow_failures:
    - rust: nightly
  fast_finish: true
$ yj .travis.yml
{
  "language": "rust",
  "os": [
    "linux",
    "osx",
    "windows"
  ],
  "rust": [
    "stable",
    "beta",
    "nightly"
  ],
  "matrix": {
    "allow_failures": [
      {
        "rust": "nightly"
      }
    ],
    "fast_finish": true
  }
}
$ echo pi: 3.1415926 | yj
{
  "pi": 3.1415926
}
$ echo pi: 3.1415926 | yj -c
{"pi":3.1415926}$

Build

Build it your self with Rust 2018, which needs a recent installation of Rust. Get Rust installed from https://rustup.rs/.

cargo build

Dependencies

~2.8–4MB
~75K SLoC