Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding JSON Data into YAML file

I am writing a fixture for my table. And a one of the coloums takes in a JSON string as a value.

The problem is the fixture is not loading failing as:

Fixture::FormatError: a YAML error occurred parsing /home/saurajeet/code/dcbox/test/fixtures/hardware.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was:   ArgumentError: syntax error on line 145, col 73: `  portslist: [{"name":"ob1","port_num":0,"port_type":"network"},{"name":"ob2","port_nu'..... 

Any solutions to this.

like image 603
Saurajeet Avatar asked Mar 02 '12 11:03

Saurajeet


People also ask

Can I use JSON in YAML?

If you want to parse JSON then you have to use the YAML parser as JSON is a subset of YAML. Moreover, JSON can be converted into YAML. YAML also has JSON in its configuration files. YAML not only permits user-defined data types but also allows explicit data typing.

Is YAML more readable than JSON?

YAML, depending on how you use it, can be more readable than JSON. JSON is often faster and is probably still interoperable with more systems. It's possible to write a "good enough" JSON parser very quickly.

What is the difference between YAML and JSON data structure?

Unlike JSON, YAML uses the indentations just like in Python to show the levels in the data. The key/value pairs are separated with a colon and the lists begin with a hyphen in YAML. And also YAML files are written with the extension YML in some places and both .

Is all YAML valid JSON?

There's some talk on the net about how JSON can be parsed by YAML parsers. However, that still doesn't quite make JSON as suitable as YAML, only YAML as JSON. I find this very readable, the minimal syntax required to convey a meaning.


1 Answers

I believe taking it into quotes should do the trick:

portslist: '[{"name":"ob1","port_type" ... }]' 
like image 57
Vlad Khomich Avatar answered Oct 05 '22 02:10

Vlad Khomich