I have a JSON body
string in python that contains lorem ipsum
e.g.
body = '[{ "type": "paragraph", "children": [ { "text": "lorem ipsum" } ] } ]'
I want to create a lambda f-string that can take any string and place it where lorem ipsum
is. E.g.
# Returns '[{ "type": "paragraph", "children": [ { "text": "1 2 3" } ] } ]'
body("1 2 3")
Is this possible? I've tried the following but no luck:
# 1
# SyntaxError: f-string: expressions nested too deeply
body = lambda x: f'''[{ "type": "paragraph", "children": [ { "text": "{x}" } ] } ]'''
# 2
# KeyError: ' "type"'
content = '[{ "type": "paragraph", "children": [ { "text": "{x}" } ] } ]'
body = lambda x: content.format(x=x)