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.
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.
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.
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 .
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.
I believe taking it into quotes should do the trick:
portslist: '[{"name":"ob1","port_type" ... }]'
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