Method: OpenNebula::DocumentJSON#to_json

Defined in:
lib/opennebula/document_json.rb

#to_json(pretty_generate = true) ⇒ String

Generates a json representing the object

Parameters:

  • pretty_generate (true, false) (defaults to: true)

Returns:

  • (String)

    json representing the object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/opennebula/document_json.rb', line 109

def to_json(pretty_generate=true)
    hash = self.to_hash

    body = hash['DOCUMENT']['TEMPLATE']["#{template_tag}"]
    if body
        body_hash = JSON.parse(body)
        hash['DOCUMENT']['TEMPLATE']["#{template_tag}"] = body_hash
    end

    if pretty_generate
        JSON.pretty_generate hash
    else
        hash.to_json
    end
end