项目作者: mbrukman

项目描述 :
Convert YAML to JSON and vice versa
高级语言: Shell
项目地址: git://github.com/mbrukman/yaml2json.git
创建时间: 2019-12-09T20:28:49Z
项目社区:https://github.com/mbrukman/yaml2json

开源协议:Apache License 2.0

下载


yaml2json

Python build status
Go 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:

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

Convert YAML → JSON:

  1. # read from stdin
  2. $ [... generate some YAML...] | yaml2json
  3. # read from a file
  4. $ yaml2json foo.yaml

Convert JSON → YAML:

  1. # read from stdin
  2. $ [... generate some JSON...] | json2yaml
  3. # read from a file
  4. $ 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.