Sha256: 95b3811506f06c3d84b96275cb9742d2db408b2837acebeed123502ff9d9ca4a

Contents?: true

Size: 657 Bytes

Versions: 9

Compression:

Stored size: 657 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)

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

          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

9 entries across 9 versions & 1 rubygems

Version Path
iostreams-1.1.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.0.0 lib/io_streams/tabular/parser/json.rb
iostreams-1.0.0.beta7 lib/io_streams/tabular/parser/json.rb
iostreams-1.0.0.beta6 lib/io_streams/tabular/parser/json.rb
iostreams-1.0.0.beta5 lib/io_streams/tabular/parser/json.rb
iostreams-1.0.0.beta4 lib/io_streams/tabular/parser/json.rb
iostreams-1.0.0.beta3 lib/io_streams/tabular/parser/json.rb
iostreams-1.0.0.beta2 lib/io_streams/tabular/parser/json.rb
iostreams-1.0.0.beta lib/io_streams/tabular/parser/json.rb