tolerate_json 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tolerate_json/version.rb +1 -1
- data/lib/tolerate_json.rb +1 -1
- data/spec/lib/tolerate_json_spec.rb +7 -0
- metadata +1 -1
data/lib/tolerate_json.rb
CHANGED
@@ -19,7 +19,7 @@ module TolerateJson
|
|
19
19
|
|
20
20
|
json = json.to_s.gsub(/\{[\s+]\"/, "{\"").gsub(/\{(\s+)\"/, "{\"").gsub(/\"(\s+)\}/, "\"}").gsub(/true(\s+)\}/, "true}").gsub(/false(\s+)\}/, "false}").gsub(/\",(\s+)\"/, '","')
|
21
21
|
|
22
|
-
json = json.gsub("},", "},\n").gsub("],", "],\n").gsub("{[", "{\n[").gsub("}]", "}\n]").gsub("[{", "[\n{").gsub("]}", "]\n}").gsub("{\"", "{\n\"").gsub("\"}", "\"\n}").gsub("\",\"", "\",\n\"").gsub(":true,\"", ":true,\n\"").gsub(":false,\"", ":false,\n\"").gsub(":true}", ":true\n}").gsub(":false}", ":false\n}").gsub(/\:(\d+),\"/) { ":#{$1},\n\"" }.gsub(/\:(\d+),\"/,":\1,\n\"")
|
22
|
+
json = json.gsub("},", "},\n").gsub("],", "],\n").gsub("{[", "{\n[").gsub("}]", "}\n]").gsub("[{", "[\n{").gsub("]}", "]\n}").gsub("{\"", "{\n\"").gsub("\"}", "\"\n}").gsub("\",\"", "\",\n\"").gsub(":true,\"", ":true,\n\"").gsub(":false,\"", ":false,\n\"").gsub(":true}", ":true\n}").gsub(":false}", ":false\n}").gsub(/:(\d+)}/) { ":#{$1}\n}" }.gsub(/\:(\d+),\"/) { ":#{$1},\n\"" }.gsub(/\:(\d+),\"/,":\1,\n\"")
|
23
23
|
|
24
24
|
output = []
|
25
25
|
|
@@ -52,6 +52,13 @@ describe TolerateJson do
|
|
52
52
|
expect(t.pretty_print_json(unformatted)).to eq(formatted)
|
53
53
|
end
|
54
54
|
|
55
|
+
it "should separate numbers and closing curly braces with cr" do
|
56
|
+
unformatted = '{"qux":{"foo":1}, "quux":"quuux"}'
|
57
|
+
formatted= "{\n \"qux\":{\n \"foo\":1\n },\n \"quux\":\"quuux\"\n}\n"
|
58
|
+
|
59
|
+
expect(t.pretty_print_json(unformatted)).to eq(formatted)
|
60
|
+
end
|
61
|
+
|
55
62
|
it "should include only one cr at the end of the result" do
|
56
63
|
unformatted = "{}\n\n\n"
|
57
64
|
formatted= "{\n}\n"
|