I'm working with configuration files so I need to convert JSON to YAML. For example I have yaml file:
{
"foo": "bar",
"baz": [ "qux","quxx"],
"corge": null,
"grault": 1,
"garply": true,
"waldo": "false",
"fred": "undefined",
"emptyArray": [],
"emptyObject": {},
"emptyString": ""
}
The result should be yaml:
foo: "bar"
baz:
- "qux"
- "quxx"
corge: null
grault: 1
garply: true
waldo: "false"
fred: "undefined"
emptyArray: []
emptyObject: {}
emptyString: ""
Could you help me?
If you need convert JSONobject to yaml (string). you need. Firstly get json string, then map, after that you can convert to yaml. Here the code:
http://jsontoyaml.com/
this website may can help you. It can be used in Bash, JavaScript, JavaScript (browser only), Ruby, Python, Perl, Java..
Here's a one liner for a file, suitable for sticking in a bash script. This should work on most default pythons on most systems:
python -c 'import json; import yaml; print(yaml.dump(json.load(open("inputfile"))))'
You can convert JSON to YAML it with two lines of code in Jackson:
You will need to add dependencies to Jackson Core, DataBind and DataFormat YAML. Below is a snippet for Gradle: