Hi,
I have an xml which i need in ruby json format
I use the below code :
data=Hash.from_xml(xml).to_json()
where xml contains the xml data.
i get the result in the below format :
{‘responseHeader’:{‘status’:0,‘QTime’:0}}
but i require the result as :
{
‘responseHeader’=>{
‘status’=>0,
‘QTime’=>0}
}
Kindly help
Smp Mp wrote:
I use the below code :
data=Hash.from_xml(xml).to_json()
where xml contains the xml data.
i get the result in the below format :
{‘responseHeader’:{‘status’:0,‘QTime’:0}}
That looks like valid JSON to me.
but i require the result as :
{
‘responseHeader’=>{
‘status’=>0,
‘QTime’=>0}
}
That’s not valid JSON. You mean you want a Ruby Hash? Try
data = Hash.from_xml(xml)
(there’s no point converting it into JSON if you’re going to JSON.parse
it back into a hash)