Skip to content

Instantly share code, notes, and snippets.

@blalor
Last active January 7, 2020 15:14
Show Gist options
  • Save blalor/52779cc1345e1c0a4c9d06f903d62b4f to your computer and use it in GitHub Desktop.
Save blalor/52779cc1345e1c0a4c9d06f903d62b4f to your computer and use it in GitHub Desktop.
Convert YAML to JSON

yaml2json

Quick and dirty CLI tool for converting yaml to json.

example

[:~] 1 $ yaml2json <( echo -e '---\nfoo:\n- bar\n- baz' )
{
    "foo": [
        "bar",
        "baz"
    ]
}
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import sys, yaml, json
import codecs
with codecs.open(sys.argv[1], encoding="utf-8") as ifp:
json.dump(yaml.load(ifp), codecs.getwriter("utf-8")(sys.stdout), indent=4, ensure_ascii=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment