Sha256: 3bf25669b623ee9390c16cdb7c219de9840a0545e87cc5e1a078a32551c4b5b9

Contents?: true

Size: 631 Bytes

Versions: 20

Compression:

Stored size: 631 Bytes

Contents

require "json"
module IOStreams
  class Tabular
    module Parser
      # For parsing a single line of JSON at a time
      class Json < Base
        def parse(row)
          return row if row.is_a?(::Hash)

          raise(IOStreams::Errors::TypeMismatch, "Format is :json. Invalid input: #{row.class.name}") unless row.is_a?(String)

          JSON.parse(row)
        end

        # Return the supplied array as a single line JSON string.
        def render(row, header)
          hash = header.to_hash(row)
          hash.to_json
        end

        def requires_header?
          false
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
iostreams-1.10.3 lib/io_streams/tabular/parser/json.rb
iostreams-1.10.2 lib/io_streams/tabular/parser/json.rb
iostreams-1.10.1 lib/io_streams/tabular/parser/json.rb
iostreams-1.10.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.9.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.8.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.7.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.6.2 lib/io_streams/tabular/parser/json.rb
iostreams-1.6.1 lib/io_streams/tabular/parser/json.rb
iostreams-1.6.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.5.1 lib/io_streams/tabular/parser/json.rb
iostreams-1.5.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.4.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.3.3 lib/io_streams/tabular/parser/json.rb
iostreams-1.3.2 lib/io_streams/tabular/parser/json.rb
iostreams-1.3.1 lib/io_streams/tabular/parser/json.rb
iostreams-1.3.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.2.1 lib/io_streams/tabular/parser/json.rb
iostreams-1.2.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.1.1 lib/io_streams/tabular/parser/json.rb