0
value  = '{"a" : 0, "b": 6, "c" : {REPLACE}}'
replace = {'REPLACE' : "Replace String"}

value.format(**replace)
value.format(replace) 

is giving me error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: '"a"'
Tom Karzes
  • 22,815
  • 2
  • 22
  • 41

2 Answers2

0

Unfortunately { braces are part of the formatting language to escape them you need to double them {{, so:

In []:
value  = '{{"a" : 0, "b": 6, "c" : {REPLACE}}}'
replace = {'REPLACE' : "Replace String"}

value.format(**replace)

Out[]:
'{"a" : 0, "b": 6, "c" : Replace String}'
AChampion
  • 29,683
  • 4
  • 59
  • 75
0

You have to escape the {} with another {}. Here is an example:

'{{"a" : 0, "b": 6, "c" : "{}"}}'.format("Replace String")

Refer this for detailed explanation.

Kaushal28
  • 5,377
  • 5
  • 41
  • 72