Skip to content

Commit

Permalink
Add a script to investigate JSON.load and JSON.parse
Browse files Browse the repository at this point in the history
According to rurema/doctree/issues/2646, `JSON.load` calls `JSON.parse`
internally. But I'm not sure it is true.
This script investigate the behaviour then I learned it is true.
  • Loading branch information
pocke committed Jan 15, 2022
1 parent da21a8d commit f65b1e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 2022/1/16/json_load_and_parse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'json'
require 'trace_location'

TraceLocation.trace(format: :log) do
JSON.load('{"foo": 42}')
end
13 changes: 13 additions & 0 deletions 2022/1/16/trace_location-2022011601011642265241.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Logged by TraceLocation gem at 2022-01-16 01:47:21 +0900
https://github.com/yhirano55/trace_location

[Tracing events] C: Call, R: Return

C /home/pocke/.rbenv/versions/trunk/lib/ruby/3.2.0/json/common.rb:557 [JSON.load]
C /home/pocke/.rbenv/versions/trunk/lib/ruby/3.2.0/json/common.rb:215 [JSON.parse]
C /home/pocke/.rbenv/versions/trunk/lib/ruby/3.2.0/json/common.rb:126 [JSON.create_id]
R /home/pocke/.rbenv/versions/trunk/lib/ruby/3.2.0/json/common.rb:128 [JSON.create_id]
R /home/pocke/.rbenv/versions/trunk/lib/ruby/3.2.0/json/common.rb:217 [JSON.parse]
R /home/pocke/.rbenv/versions/trunk/lib/ruby/3.2.0/json/common.rb:572 [JSON.load]

Result: {"foo"=>42}

0 comments on commit f65b1e4

Please sign in to comment.