Skip to content

Instantly share code, notes, and snippets.

@xenithorb
Last active December 7, 2018 14:16
Show Gist options
  • Save xenithorb/e90713534624c93a834a92c2a0c6ee28 to your computer and use it in GitHub Desktop.
Save xenithorb/e90713534624c93a834a92c2a0c6ee28 to your computer and use it in GitHub Desktop.

Revisions

  1. xenithorb revised this gist Dec 7, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions json-yaml-tools.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Please place these in ~/.bashrc or equivalent

    yaml2json() {
    python < "${1:-/dev/stdin}" <(
    python3 < "${1:-/dev/stdin}" <(
    cat <<-EOF
    import sys, yaml, json
    json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)
    @@ -10,7 +10,7 @@ yaml2json() {
    }

    json2yaml() {
    python < "${1:-/dev/stdin}" <(
    python3 < "${1:-/dev/stdin}" <(
    cat <<-EOF
    import sys, yaml, json
    yaml.safe_dump( json.load(sys.stdin),
  2. xenithorb created this gist Jan 29, 2018.
    23 changes: 23 additions & 0 deletions json-yaml-tools.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # Please place these in ~/.bashrc or equivalent

    yaml2json() {
    python < "${1:-/dev/stdin}" <(
    cat <<-EOF
    import sys, yaml, json
    json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)
    EOF
    )
    }

    json2yaml() {
    python < "${1:-/dev/stdin}" <(
    cat <<-EOF
    import sys, yaml, json
    yaml.safe_dump( json.load(sys.stdin),
    sys.stdout,
    explicit_start=True,
    default_flow_style=False
    )
    EOF
    )
    }