I have the following string:
'{
"key1": "val1",
"key2": ["a","b", 3],
"key3": {"foo": 27, "bar": [1, 2, 3]}
}'
I want to parse only one level so result should be a one level dictionary with key, and value should be just a string(don’t need to parse it)
For given string it should return following dictionary:
{
"key1": "val1",
"key2": "['a','b', 3]",
"key3": "{'foo': 27, 'bar': [1, 2, 3]}"
}
Is there a fast way to do it? Without parsing whole string to json and convert all values back to strings.
I think you can solve this using regex, it is working for me:
But I dont know if this is faster, you need try using your data.
[EDIT]
Yes, it is faster. I tried the scripts below and the regex version is 5 times faster.
using json module:
using regex: