Class: Zona::OZonesJSON
- Inherits:
-
Object
- Object
- Zona::OZonesJSON
- Defined in:
- zona/OZonesJSON.rb
Overview
Several class methods regarding the handling of JSON descriptions for the OZones utilities.
Class Method Summary (collapse)
-
+ (Hash, Zona::Error) build_json(json_str, root_element)
Build an element description hash.
- + (Object) parse_json(json_str, root_element)
-
+ (String, Zona::Error) to_json(hash_to_convert)
Generates a pretty JSON string from a hash.
Class Method Details
+ (Hash, Zona::Error) build_json(json_str, root_element)
Build an element description hash.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'zona/OZonesJSON.rb', line 30 def self.build_json(json_str, root_element) begin parser = JSON.parser.new(json_str, {:symbolize_names => true}) hash = parser.parse root_sym = root_element.to_sym if hash.has_key?(root_sym) return hash[root_sym] end Error.new("Error parsing JSON:\ root element not present") rescue => e Error.new(e.) end end |
+ (Object) parse_json(json_str, root_element)
49 50 51 |
# File 'zona/OZonesJSON.rb', line 49 def self.parse_json(json_str, root_element) OZonesJSON.build_json(json_str, root_element) end |
+ (String, Zona::Error) to_json(hash_to_convert)
Generates a pretty JSON string from a hash
56 57 58 59 60 61 62 |
# File 'zona/OZonesJSON.rb', line 56 def self.to_json(hash_to_convert) begin JSON.pretty_generate(hash_to_convert) rescue Exception => e Error.new(e.) end end |