6
vane
4y

Converting javascript/ typescript Map to json
or python date to json

or anything complicated to json is mostly ending with implementing serialization patterns

With date it’s so annoying cause we have iso standards that every language implemented or have libraries

so typescript doesn’t recognize Map<string, string> so you have to convert it to array and then to object

with python you need to make your own serializer / deserializer

So much waste of power usage that if only Greta know it she would say ‘how dare you!’
It can stop global warming.

Comments
  • 1
    Can you clarify "doesn't recognize Map<string, string>"?
  • 1
    Python dict is just a map...

    json.dumps?
  • 1
    @SortOfTested typescript Map is javascript es6 Map and coming from java for me variable Map<string, string> is no different then object {‘foo’:’bar’} that is serializable by JSON.stringify cause json allows only strings as objects.

    https://stackoverflow.com/questions...
  • 0
    @AlgoRythm yeah but to get datetime from string you need to provide custom serializer cause json specification doesn’t recognize date
  • 1
    @vane
    Yeah, no way around that. You can't deserialize to a typescript map. Under the hood it's just an array[[k,v]].

    You can use a reviver in json.parse however, scan the symbol and do a transformation.

    https://developer.mozilla.org/en-US...

    Or type it as {[key: string]: string}. Different semantics, but same result.
Add Comment