#to_json inserting invalid new lines
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 597
- Forks
- 223
- Avg merge
- 11h 23m
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with YAML.to_json using the hash and description shown in the report, then inspect the Psych YAML-to-JSON conversion path. Done means the resulting JSON is valid and preserves the description without inserting a newline into its value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby, yaml
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100