lib/jsonify/builder.rb in jsonify-0.2.0 vs lib/jsonify/builder.rb in jsonify-0.3.0

- old
+ new

@@ -55,20 +55,21 @@ def tag!(sym, args=nil, &block) method_missing(sym, *args, &block) end # Compiles the JSON objects into a string representation. - # If initialized with +:verify => true+, the compiled result will be verified by attempting to re-parse it using +JSON.parse+. - # If initialized with +:format => :pretty+, the compiled result will be parsed and regenerated via +JSON.pretty_generate+. + # If initialized with +:verify => true+, the compiled result will be verified by attempting to re-parse it using +MultiJson.decode+. + # If initialized with +:format => :pretty+, the compiled result will be parsed and encoded via +MultiJson.encode(<json>, :pretty => true)+ # This method can be called without any side effects. You can call +compile!+ at any time, and multiple times if desired. # # @raise [TypeError] only if +:verify+ is set to true # @raise [JSON::ParseError] only if +:verify+ is set to true def compile! - result = (@stack[0] || {}).to_json - JSON.parse(result) if @verify - @pretty ? JSON.pretty_generate(JSON.parse(result)) : result + result = (@stack[0] || {}).encode_as_json + MultiJson.decode(result) if @verify + result = MultiJson.encode(MultiJson.decode(result), :pretty => true) if @pretty + result end # Stores the key and value into a JSON object # @param key the key for the pair # @param value the value for the pair @@ -184,10 +185,10 @@ # current value at the top of the stack. # # @param [String] json_string a full JSON string (e.g. from a rendered partial) def ingest!(json_string) return if json_string.empty? - res = Jsonify::Generate.value(JSON.parse(json_string)) + res = Jsonify::Generate.value(MultiJson.decode(json_string)) current = @stack[@level] if current.nil? @stack[@level] = res elsif JsonObject === current if JsonObject === res