-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Information is lost when converting hexadecimal value from xml to json. #852
Comments
@anki006 Thanks for bringing this issue up, will look into it. |
xml <color> <color_type>primary</color_type> <value>008E97</value> </color> may be converted to json {
"color": {
"color_type": "primary",
"value": "008E97"
},
"#omit-xml-declaration": "yes"
} |
Hello @stleary Any update on this issue? |
Pretty sure this is just another case of someone not using the "keep strings" setting in the xml parser |
@anki006 After some review - JSON does not recognize hex as a valid type. In this case, the 'e' char is causing the string to be interpreted as a number in scientific notation, which is supported. Agreed, you should be keeping the values as strings. For example, Where str contains the XML to be converted to JSON. |
While parsing an XML which has hexadecimal value which starts with number (0-9), for example below:
<color> <color_type>primary</color_type> <value>008E97</value> </color>
The equivalent json is formed is:
"color": [ { "color_type": "primary", "value": 8e+97 } ]
However, if the hexadecimal value starts with string, its equivalent json is also a string.
<color> <color_type>primary</color_type> <value>fc4c02</value> </color>
The equivalent json is formed is:
"color": [ { "color_type": "primary", "value": "fc4c02" } ]
The code fails to handle hexadecimal conversion and creates ambiguity by treating it as number and string both. I assume, if there is ambiguities like this, we need to stick to string rather than converting to number.
The text was updated successfully, but these errors were encountered: