Why Does Psych Yaml Interpreter Add Line Breaks Around 80 Characters

why does psych yaml interpreter add line breaks around 80 characters?

You'll have to configure psych’s #to_yaml options. You'll most likely find it here:

ruby-1.9.3-p125/ext/psych/emitter.c

And then you can do something like this:

yaml.to_yaml(options = {:line_width => -1})

Writing to YAML file with File.open wraps longer lines

Turns out this was actually answered previously in "why does psych yaml interpreter add line breaks around 80 characters?". I was searching for the wrong thing.

Doing something like

yaml.to_yaml(:options => {:line_width => -1})

keeps the lines from wrapping.

Why i'm getting Psych::SyntaxError while translating YAML data back into working objects

You're missing some indentation. YML isn't white space agnostic. Try using this data instead:

yaml_string = <<END_OF_DATA
---
- !ruby/object:Person
age: 45
name: Jimmy
- !ruby/object:Person
age: 23
name: Laura Smith
END_OF_DATA

Documentation for Psych to_yaml options?

Deep in the guts of ruby-1.9.3-p125/ext/psych/emitter.c I found three options:

  • indentation - The level must be less than 10 and greater than 1.
  • line_width - Set the preferred line width.
  • canonical - Set the output style to canonical, or not (true/false).

And they work!

Why the difference in behavior of YAML parsers (syck and psych)?

As @matt had mentioned, the answer is this pull request: https://github.com/ruby/ruby/commit/9f688d53c2b5af5960d1e8d8fb09b26aa9d8b5f9



Related Topics



Leave a reply



Submit