'Enclose all characters,strings,timestamp and numbers in double quotes using re
I have a dictionary which does not have quotes on them. objective is to enclose them on quotes
code that works (python)
newstring = """{field1:{abc:1, "def":2,geh:{dt:2019-07-23T23:00:01.000Z, lp:229.99, op = [dsa,fds,1]}}}"""
textdata = "([\w.]+)"
replacer = re.compile(textdata)
data2 = replacer.sub(r'"\1"', newstring)
above code encloses all strings into quotes. however the timestamp is broken into multiple part the timestamp is expected to be in ISO8601 format.
i fount epxression which matches the format
"""[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?"""
but i am having issue making them both work together. could someone help on how to combine two expressions.
expected result is
{"field1":{"abc":"1", "def":"2","geh":{"dt":"2019-07-23T23:00:01.000Z", "lp":"229.99", "op" = ["dsa","fds","1"]}}}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
