Skip to content

#to_json inserting invalid new lines #243

@akostadinov

Description

@akostadinov

Perhaps I'm beating the dead horse, in any case, I was curious to see what happens when I use YAML.to_json instead the standard JSON library. It seems the Psych version inserts incorrectly new lines into JSON, rendering it invalid:

[20] pry(#<DefaultWorld>)> s
=> {"apiVersion"=>"v1",
 "displayName"=>"OpenShift 3 Demo",
 "description"=>"This is the first demo project with OpenShift v3",
 "kind"=>"ProjectRequest",
 "metadata"=>{"name"=>"demmol5"}}
[25] pry(#<DefaultWorld>)> Kernel.puts YAML.to_json(s)
{"apiVersion": "v1", "displayName": "OpenShift 3 Demo", "description": "This is the
    first demo project with OpenShift v3", "kind": "ProjectRequest", "metadata": {
    "name": "demmol5"}}
=> nil
[26] pry(#<DefaultWorld>)> YAML::VERSION
=> "2.0.8"

You can see there is a new line inserted into the description value.

I'm switching to the standard JSON approach but thought it would be nice to be fixed and possibly save somebody the hassle.

Don't take me wrong, YAML is nice and using Psych for YAML all the time. Thanks a lot for the awesome lib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions