Skip to content

Instantly share code, notes, and snippets.

@y13i
Last active June 21, 2016 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y13i/4d93b5097f11373f8a04 to your computer and use it in GitHub Desktop.
Save y13i/4d93b5097f11373f8a04 to your computer and use it in GitHub Desktop.
GoでJSONとYAMLを相互変換するツールを作った ref: http://qiita.com/y13i/items/ee93ea07ecff11990676
$ cat example.json
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
$ j2y example.json
employees:
- firstName: John
lastName: Doe
- firstName: Anna
lastName: Smith
- firstName: Peter
lastName: Jones
$ j2y -o example.yml example.json
$ cat example.yml
employees:
- firstName: John
lastName: Doe
- firstName: Anna
lastName: Smith
- firstName: Peter
lastName: Jones
$ j2y -r example.yml
{
"employees": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Anna",
"lastName": "Smith"
},
{
"firstName": "Peter",
"lastName": "Jones"
}
]
}
$ j2y -r -m example.yml
{"employees":[{"firstName":"John","lastName":"Doe"},{"firstName":"Anna","lastName":"Smith"},{"firstName":"Peter","lastName":"Jones"}]}
$ j2y -e '{"employees":[{"firstName":"John","lastName":"Doe"},{"firstName":"Anna","lastName":"Smith"},{"firstName":"Peter","lastName":"Jones"}]}'
employees:
- firstName: John
lastName: Doe
- firstName: Anna
lastName: Smith
- firstName: Peter
lastName: Jones
$ echo '{"employees":[{"firstName":"John","lastName":"Doe"},{"firstName":"Anna","lastName":"Smith"},{"firstName":"Peter","lastName":"Jones"}]}' | j2y
employees:
- firstName: John
lastName: Doe
- firstName: Anna
lastName: Smith
- firstName: Peter
lastName: Jones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment