I have a dict object with this type of structure
{"a": '{"b": "c"}'}
I'd like to use a loop to insert different values into the "c"
area for use elsewhere in a project. The problem is that the single quotes around the b and c make this more difficult.
I tried:
{"a": '{"b": "{}"}.format("d")'}
But this returns the dict without evaluating the format function.
I also tried:
{"a": '{"b": "{}"}'.format("d")}
But this returns an error. I've gone through 2 hours of combinations and SO questions like (this, this, and this) but have realized that I need the help of someone who knows what they're doing.
A viable solution would look like:
x = {"a": '{"b": "c"}'}
val = "d"
magic(x, val)
>>> {"a": '{"b": "d"}'}
Note: To the comments asking "why this format"? I am not creating these objects and so they are not my choice. I have an api that I have connected to. I am pulling the current data, changing it, and uploading it back. There is no opportunity to "not use a string literal". That is what the api post is expecting. I am not in a position now to ask the maintainers to change their storage system