I am trying to convert a JavaScript object into a Python dict for processing and later export to JSON. So far easy peasy by using demjson3.
BUT: since there are undefined values it will convert these into demjson3.undefined.
Those demjson3.undefined are not JSON serializable and therefore raise a TypeError.
I am aware of what the difference of null and undefined is, but since there is no Python equivalent for undefined what is best practice to handle it? IMHO: None
edit: the served JS obj is not under my control and I have (in this use case) to process what is being served.
Is there a demjson3 parameter I am not yet aware of, do i actually have to provide a custom serializer for something so obvious or is some_js_obj.replace('undefined', 'null') the way to go?
How do you handle this?
Example:
some_js_obj = locationAddress: {
geoCode: "133713371337",
city: "Berlin",
zip: "10318",
isFullAddress: false,
houseNumber: undefined,
street: undefined,
qualifiedGeoIds: {
continentId: "1",
countryId: "111",
regionId: "3",
cityId: "42",
districtId: "13"
}
}
converts into using demjson3:
some_py_dict = {'locationAddress': {'geoCode': '133713371337',
'city': 'Berlin',
'zip': '10318',
'isFullAddress': False,
'houseNumber': demjson3.undefined,
'street': demjson3.undefined,
'qualifiedGeoIds': {
'continentId': '1',
'countryId': '111',
'regionId': '3',
'cityId': '42',
'districtId': '13'}}}