class Oj::Saj
A SAX style parse handler for JSON hence the acronym SAJ for Simple API for JSON. The Oj::Saj handler class should be subclassed and then used with the Oj::Saj key_parse() method. The Saj methods will then be called as the file is parsed.
@example
require 'oj' class MySaj < ::Oj::Saj def initialize() @hash_cnt = 0 end def hash_start(key) @hash_cnt += 1 end end cnt = MySaj.new() File.open('any.json', 'r') do |f| Oj.saj_parse(cnt, f) end
To make the desired methods active while parsing the desired method should be made public in the subclasses. If the methods remain private they will not be called during parsing.
def hash_start(key); end def hash_end(key); end def array_start(key); end def array_end(key); end def add_value(value, key); end def error(message, line, column); end
Public Class Methods
new()
click to toggle source
Create a new instance of the Saj handler class.
# File lib/oj/saj.rb, line 39 def initialize() end
Private Instance Methods
add_value(value, key)
click to toggle source
# File lib/oj/saj.rb, line 59 def add_value(value, key) end
array_end(key)
click to toggle source
# File lib/oj/saj.rb, line 56 def array_end(key) end
array_start(key)
click to toggle source
# File lib/oj/saj.rb, line 53 def array_start(key) end
error(message, line, column)
click to toggle source
# File lib/oj/saj.rb, line 62 def error(message, line, column) end
hash_end(key)
click to toggle source
# File lib/oj/saj.rb, line 50 def hash_end(key) end
hash_start(key)
click to toggle source
To make the desired methods active while parsing the desired method should be made public in the subclasses. If the methods remain private they will not be called during parsing.
# File lib/oj/saj.rb, line 47 def hash_start(key) end