Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to embed YAML into a JSON payload?

Tags:

json

yaml

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"
       }
    }
like image 486
Swaroop Avatar asked Dec 29 '17 16:12

Swaroop


People also ask

Is YAML compatible with JSON?

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.

Can we convert YAML to JSON?

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.

Which is supported YAML not supported by JSON?

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.


1 Answers

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
like image 171
tinita Avatar answered Oct 23 '22 03:10

tinita