Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the proper and reliable way to store an XML string as a JSON property?

Tags:

json

xml

I want to store a string which itself is an XML string as a property of an JSON object , what's the reliable and proper way of dong this? Should I first encode the XML data into BASE64 first prior saving it to an JSON object, due to the fact that JSON does not support binary data?

Example of data I want to store:

{ 
"string1" : "<xml>...moderately complex XML...</xml>" 
} 
like image 240
Edwin Yip Avatar asked May 28 '10 12:05

Edwin Yip


1 Answers

Actually base 64 should work. But you might want to mark the property so it is clear.

{
    "Property" : {
        "Type" : "XML",
        "Encoding" : "Base64",
        "Value" : "PFhNTD48WE1MPjxYTUw+PC9YTUw+PC9YTUw+PC9YTUw+"
    }
}
like image 193
ChaosPandion Avatar answered Nov 08 '22 05:11

ChaosPandion