Project

General

Profile

Bug #4244

Psych.to_json generate incorrect JSON

Added by nagachika (Tomoyuki Chikanaga) over 9 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 1.9.3dev (2011-01-01 trunk 30447) [x86_64-darwin10.5.0]
Backport:
[ruby-core:34186]

Description

=begin
Psych.to_json could be presumed to return JSON because of its name.
But Psych.to_json generate single-quoted string. It isn't valid JSON format.

require "psych"
=> true
Psych.to_json("aaa")
=> "'aaa'\n"
Psych.to_json(["a","b","c"])
=> "['a', 'b', 'c']\n"
require "json"
=> true
JSON.parse(Psych.to_json(["a","b","c"]))
JSON::ParserError: 376: unexpected token at ''a', 'b', 'c']
'
=end

#1

Updated by yugui (Yuki Sonoda) over 9 years ago

  • Assignee set to tenderlovemaking (Aaron Patterson)

=begin

=end

#2

Updated by yugui (Yuki Sonoda) over 9 years ago

  • Status changed from Open to Assigned
  • Priority changed from 3 to Normal

=begin

=end

#3

Updated by Anonymous over 9 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r30587.
Tomoyuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/psych/lib/psych/visitors/json_tree.rb (visit_String): JSON strings should be dumped with double quotes. [ruby-core:34186]
  • test/psych/test_json_tree.rb: test for double quotes =end

Also available in: Atom PDF