Sha256: 2cf8d508f2f76f2bbe2808dfee0d07ba1da41a5116eef9856a3c68813b126cbd

Contents?: true

Size: 631 Bytes

Versions: 13

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

13 entries across 13 versions & 1 rubygems

Version Path
iostreams-0.20.3 lib/io_streams/tabular/parser/json.rb
iostreams-0.20.2 lib/io_streams/tabular/parser/json.rb
iostreams-0.20.1 lib/io_streams/tabular/parser/json.rb
iostreams-0.20.0 lib/io_streams/tabular/parser/json.rb
iostreams-0.19.0 lib/io_streams/tabular/parser/json.rb
iostreams-0.18.0 lib/io_streams/tabular/parser/json.rb
iostreams-0.17.3 lib/io_streams/tabular/parser/json.rb
iostreams-0.17.2 lib/io_streams/tabular/parser/json.rb
iostreams-0.17.1 lib/io_streams/tabular/parser/json.rb
iostreams-0.17.0 lib/io_streams/tabular/parser/json.rb
iostreams-0.16.2 lib/io_streams/tabular/parser/json.rb
iostreams-0.16.1 lib/io_streams/tabular/parser/json.rb
iostreams-0.16.0 lib/io_streams/tabular/parser/json.rb