A command line tool for converting between YAML and JSON and vice versa.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


#NAME y2j, j2y, yq - filters to convert JSON to YAML, YAML to JSON and YAML to YAML.

#SYNOPSIS # convert from YAML to JSON y2j < yaml > json j2y -d < yaml > json

# convert from YAML to JSON with optional trailing jq transformation
y2j {jq-filter} < yaml

# convert from JSON to YAML
j2y < json > yaml
y2j -d < json > yaml

# convert from JSON to YAM with optional leading jq transformation
j2y {jq-filter} < json > yaml

# convert YAML to JSON, run jq, convert back to YAML
yq {jq-filter} < yaml > yaml

# create an installer that will install y2j.sh into /usr/local/bin, then run that script with bash
y2j.sh installer /usr/local/bin | sudo bash


This package provides filters for transforming JSON to YAML, YAML to JSON and YAML to YAML.

YAML to YAML transformations are performed by applying a jq filter to a JSON transformation of the YAML input stream with y2j and transforming the resulting JSON stream back to YAML with j2y.

The script will use the local instances of jq, python and the required python modules if they exist locally or will use a docker container based on the wildducktheories/y2j image otherwise.


docker run --rm wildducktheories/y2j y2j.sh installer /usr/local/bin | sudo bash

Replace /usr/local/bin with a different directory to specify a different installation location or omit to default to /usr/local/bin.

If the installer fails with complaints about lack of a running docker daemon or failure to find a wildducktheories/y2j image, consider changing sudo bash to sudo -E bash so that root inherits the current user's docker environment.


echo '{ "foo": [ { "id": 1 } , {"id": 2 }] }' | j2y


- id: 1
- id: 2

##j2y - with jq pre-stage

echo '{"foo": "bar"}{"foo": "baz"}' | j2y -s .


- foo: bar
- foo: baz


	y2j <<EOF
- id: 1
- id: 2
) | jq -c .




yq '.foo=(.foo[]|select(.id == 1)|[.])' <<EOF
- id: 1
- id: 2


- id: 1


  • y2j and yq only support the subset of YAML streams that can be losslessly represented in JSON - that is: trees. Graphs, anchors and references are not supported.
  • j2y only supports reading of a single JSON object or a single JSON array from stdin. If the JSON input contains multiple objects, consider using '-s .' with j2y to slurp the input into a single JSON array.
  • yq only supports jq-filters that are guaranteed to produce a single JSON object or array.

Behaviour with inputs or filters that do not satisfy these constraints is not defined.


Jon Seymour <jon@wildducktheories.com>


Conversions used by y2j.sh are based on the commandlinefu scripts found here:

Filtering is implemented with jq. See http://stedolan.github.io/jq/.



  • Fixed typo in installation message.
  • Support running on Linux.

Both fixes thanks to reports submitted by Henrik Holmboe.


  • Added support for yq.


  • Initial release.