Comments (2)
@gregLibert this feature already exists. You can override the conversion with the xml_fromstring
option. For example:
>>> def convert_only_int(val):
... return int(val) if val.isdigit() else val
>>> bf_int = BadgerFish(xml_fromstring=convert_only_int)
>>> dumps(bf_int.data(fromstring('<p><x>1</x><y>2.5</y><z>NaN</z></p>')))
'{"p": {"x": {"$": 1}, "y": {"$": "2.5"}, "z": {"$": "NaN"}}}'
In the example above, only the integer 1
is converted to an integer. Everything else is retained as a
float. You can write your own custom function.
Does this meet your needs?
from xmljson.
Great!
This is exactly what I'm looking for. I'm using the following conversion rule :
try:
return int(val)
except ValueError:
pass
try:
float_val = float(val)
if(float_val == float_val):
return float_val
except ValueError:
pass
return val
Thank you very much !
from xmljson.
Related Issues (20)
- Abdera child nodes incorrectly placed in same dictionaries HOT 1
- "NAN" to invalid json HOT 4
- Have you looked at jxmlease? HOT 1
- Single element array HOT 5
- Unable to specify encoding HOT 1
- None becomes "None" HOT 3
- ImportError: cannot import name 'badgerfish' HOT 5
- tail nodes not covered HOT 2
- XML namespaces getting injected into attribute names - parker covention HOT 6
- Support for JSONML HOT 2
- Handling Self Closing Tags HOT 10
- Node values (text) broken by sub-nodes HOT 3
- How to Convert Back to XML?
- Parker convention is not implemented correctly HOT 9
- Spaces are trimmed
- unclosed token: line 191784 HOT 1
- Is it possible to convert & into & not & symbol?
- Arrangement of children not preserved HOT 3
- First example in README does not match xmljson behavior version 0.2.1 HOT 1
- int in _fromstring method removing leading zero
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xmljson.