Is it possible to embed YAML into a JSON payload? And if so, How?
I'm trying to come up with a JSON request which has a embedded YAML embedded, a very large YAML file at that:
{
"deployment":{
"family":"mui",
"assemblyfile": "large YAML file here"
}
}
Although YAML looks different to JSON, YAML is a superset of JSON. As a superset of JSON, a valid YAML file can contain JSON. Additionally, JSON can transform into YAML as well. YAML itself can also contain JSON in its configuration files.
Select the YAML to JSON action from the XML Tools > JSON Tools menu. Choose or enter the YAML URL for the document you want to convert. Choose the path of the Output file that will contain the resulting JSON document.
YAML supports comments where JSON does not. We can comment anywhere in the document with a simple # character. This has proven advantageous when writing configuration files where one developer can easily describe the configuration using the comments.
So, apperently the question is about how to quote/escape the embedded text (YAML).
Try out jq, it offers a lot of sophisticated operations. This should do the trick:
# return your text properly escaped in "" quotes
jq --raw-input --slurp < file.yaml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With