Comments (2)
Hi aadamvanko.
In your code, you tried to use jsons.load
on a dict that was already (largely) deserialized on this line: withDateDict = jsons.loads(withDateStr)
. The jsons.load
function only allows dicts with types that have a JSON equivalent (i.e. str
, int
, float
, bool
, list
, tuple
, set
, dict
and NoneType
, not datetime.datetime
).
If you want to deserialize a string, you could just use jsons.loads
.
withDateStr = '''{"created":"2019-12-19T11:40:48Z"}'''
# withDateDict = jsons.loads(withDateStr) <-- No need for this
# print(withDateDict)
withDateObj = jsons.loads(withDateStr, WithDateOK) # <-- loads instead of load
withDateObj = jsons.loads(withDateStr, WithDateBad) # <-- loads instead of load
print(type(withDateObj))
print(withDateObj)
Or, if you actually intended to do it in two steps, you should use json.loads
instead:
withDateStr = '''{"created":"2019-12-19T11:40:48Z"}'''
withDateDict = json.loads(withDateStr) # <-- json instead of jsons
print(withDateDict)
withDateObj = jsons.load(withDateDict, WithDateOK)
withDateObj = jsons.load(withDateDict, WithDateBad)
print(type(withDateObj))
print(withDateObj)
Hope that helps!
Regards,
Ramon
from jsons.
Thanks for the clarification, it is kind of misleading with json
and also jsons
and both have load
and loads
and works little bit differently from what you have shown, but my code works like it should so thank you.
Regards,
Adam
from jsons.
Related Issues (20)
- Literal (and Union[Literal]) support HOT 1
- TypeError: Item in jsons.__all__ must be str, not function HOT 1
- Question about JsonSerializable.json method HOT 2
- Document issue: `dumps` should return a string? HOT 1
- Bug `with_dump` only support `json`, not support `dumps` HOT 2
- DeserializationError when loading into a class with an Optional bson.ObjectID HOT 2
- Optional and Union fields are not handled correctly HOT 2
- UserWarning: Failed to dump attribute after updating python to 3.10 HOT 2
- In nested objects, `load` is only called for the root object instead of being called for each one HOT 1
- How to make `jsons.dump()` treat `bytes` the same as Python3 `str`? HOT 2
- Deserialize JSON into Class - Ignore attributes HOT 3
- SerializationError: object of type 'abc' has no len() HOT 2
- What's the key difference between `jsons` and `pydantic`? HOT 1
- DeserializationError: Invalid type: "decimal.Decimal"
- jsons dumps fields sorted
- Test failure with Python 3.11 HOT 1
- deserialization with jsons to nested classes HOT 1
- Error: got an unexpected keyword argument 'origin'
- dicts are serialized wrongly when assigned to an attribute with an 'Any' type
- Is this project still alive ?
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 jsons.