I'm parsing a YAML file in Ruby and some of the input is causing a Psych syntax error:
require 'yaml'
example = "my_key: [string] string"
YAML.load(example)
Resulting in:
Psych::SyntaxError: (<unknown>): did not find expected key
while parsing a block mapping at line 1 column 1
from [...]/psych.rb:456:in `parse'
I received this YAML from an external API that I do not have control over. I can see that editing the input to force parsing as a string, using my_key: '[string] string'
, as noted in "Do I need quotes for strings in YAML?", fixes the issue however I don't control how the input is received.
Is there a way to force the input to be parsed as a string for some keys such as my_key
? Is there a workaround to successfully parse this YAML?
[string] string
or the string 'string`? Obviously you don't get valid yaml, so maybe you have a description from the API you use. – Bruckner<
,>
in yaml strings, even when escaped. It's a bit of a hack, but I ended up using the HTML escaped versions instead successfully (<
,>
). – Canopy