I am trying to read a yaml file similar to this
SLTs:
- requests: 600
concurrency: 50
targets:
99%: < 100
Requests per second: > 500
Notice that the key “Requests per second” has spaces in it. I have read the yaml specs in yaml.org and it seems that this is OK.
Ruby 1.9.2 came with 2 yaml libraries psych and syck.
Psych is not able to read this file
couldn't parse YAML at line 132 column 37 (Psych::SyntaxError)
Syck is able to parse it but it does not work correctly with Delayed Job (another integral part of my system).
I have tried 1.9.3 with similar results.
The engine for YAML can be changed with YAML::ENGINE.yamler = … but I would rather not play with changing the engine for each case and use a library that works correctly in both cases.
I have googled for it but could not find anything so my question is: There exists a better library than those in the Ruby standard library to process YAML ? I only need to read files.
It’s not the spaces in the key that’s causing the problem, it’s the value:
> 500.>indicates a scalar in folded style – the error is saying that after the>there should only be a comment or a newline.You’ll need to escape the values for your hash: