Git Product home page Git Product logo

yaml2json's Introduction

yaml2json

Build Status Go Report Card

This project provides a simple library and CLI for converting YAML to JSON, written separately in Python and Go.

Usage

Install the Go utilities:

$ go install github.com/mbrukman/yaml2json/cmd/{yaml2json,json2yaml}@latest

Convert YAML → JSON:

# read from stdin
$ [... generate some YAML...] | yaml2json

# read from a file
$ yaml2json foo.yaml

Convert JSON → YAML:

# read from stdin
$ [... generate some JSON...] | json2yaml

# read from a file
$ json2yaml foo.json

In all cases, the output is to stdout.

For the equivalent Python implementations, see the python directory for details.

Motivation

Some programs and utilities only support JSON as their configuration input format; however, JSON is very strict and limited (which makes it great for computers and programs), but it's insufficient for the needs of human developers. A number of issues result from humans directly editing JSON:

  • JSON does not support comments, so it's not possible to add context or annotations for why something is the way it is
  • JSON is quite verbose, requiring double quotes around each field name
  • JSON requires commas at the end of each key/value pair, but disallows a comma after the last key/value in an object — this is minor, but still somewhat tedious to have to remember to deal with

Thus, it's easier to write simple configs in YAML, but in that case, we find ourselves in need of having a simple YAML-to-JSON converter, and rather than re-implement the same simple converter within each project, I wanted to have a stand-alone project which has this already pre-built.

Why YAML?

Or, why not [another language] instead?

Because YAML is (mostly) simple, readable, and well-known. It supports comments, does not require double quotes, or commas after fields. For many use cases, what's needed is a simple hierarchical configuration format with comments for annotating rationale, providing context, or links to related work. In those cases, advanced features such as computation, reuse, or overrides are unnecessary. If you need those types of features, you can use a language such as Jsonnet, which supports templates and overrides, and it has its own conversion to JSON.

Contributing

See CONTRIBUTING.md for details.

License

Apache 2.0; see LICENSE for details.

Disclaimer

This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.

yaml2json's People

Contributors

mbrukman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lijinfeng2011

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.