Module: DbAgile::IO::JSON
- Extended by:
- TypeSafe
- Defined in:
- lib/dbagile/io/json.rb
Class Method Summary collapse
-
.from_json(input, options = {}, &block) ⇒ Object
Loads some data from a json input.
-
.to_json(data, columns = nil, buffer = "", options = {}) ⇒ ...
Outputs some data as a JSON string.
Methods included from TypeSafe
from_typesafe_relation, from_typesafe_tuple, from_typesafe_xxx, to_typesafe_relation, to_typesafe_tuple, with_type_safe_relation
Class Method Details
.from_json(input, options = {}, &block) ⇒ Object
Loads some data from a json input. If a block is given, yields it with each tuple in turn and returns nil. Otherwise returns an array of tuples.
33 34 35 36 |
# File 'lib/dbagile/io/json.rb', line 33 def from_json(input, = {}, &block) require "json" from_typesafe_xxx(::JSON::load(input), , &block) end |
.to_json(data, columns = nil, buffer = "", options = {}) ⇒ ...
Outputs some data as a JSON string
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dbagile/io/json.rb', line 11 def to_json(data, columns = nil, buffer = "", = {}) require "json" pretty, first = [:pretty], true buffer << (pretty ? "[\n" : "[") with_type_safe_relation(data, ) do |tuple| buffer << (pretty ? ",\n" : ",") unless first if pretty buffer << ::JSON::pretty_generate(tuple) else buffer << ::JSON::fast_generate(tuple) end first = false end buffer << (pretty ? "\n]" : "]") buffer end |