Class: ArrayCollection::JsonParser

Inherits:
Object
  • Object
show all
Defined in:
lib/array_collection/json_parser.rb

Overview

JSON Parser for collection

Class Method Summary collapse

Class Method Details

.json_like?(input) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'lib/array_collection/json_parser.rb', line 7

def json_like?(input)
  return false if input.nil? || input.count.zero?

  hash = input[0]
  hash.is_a?(Hash) && hash.keys.all?(String)
end

.parse_to_hash(json_like) ⇒ Object



14
15
16
# File 'lib/array_collection/json_parser.rb', line 14

def parse_to_hash(json_like)
  json_like.map { |hash| deep_string_to_symbol(hash) }
end

.parse_to_json(hashes) ⇒ Object



18
19
20
# File 'lib/array_collection/json_parser.rb', line 18

def parse_to_json(hashes)
  hashes.map { |hash| deep_stringify_keys(hash) }
end