I have a question to update json script with replace holder with python.
The code:
json_str = '''
<Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
<Statement>
<DatabaseName>{database}</DatabaseName>
<![CDATA[
{{
\"create\": {{
\"object\": {{
\"database\":\"{{{database}}}\"
}}
}}
}}
]]>
</Statement>
</Execute>'''
replaced_str = json_str.format(database='testDB')
print(replaced_str)
The output is:
<Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
<Statement>
<DatabaseName>testDB</DatabaseName>
<![CDATA[
{
"create": {
"object": {
"database":"{testDB}"
}
}
}
]]>
</Statement>
</Execute>
Anybody is familiar about how to change the curly brace escape to get the expected output from:
"database":"{testDB}" to "database":"testDB" ?
Thanks
>Solution :
Remove two of {}: From {{{database}}} to {database}:
json_str = '''
<Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
<Command>
<Statement>
<DatabaseName>{database}</DatabaseName>
<![CDATA[
{{
\"create\": {{
\"object\": {{
\"database\":\"{database}\"
}}
}}
}}
]]>
</Statement>
</Command>
<Properties />
</Execute>'''
replaced_str = json_str.format(database='testDB')
print(replaced_str)
Output:
<Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
<Command>
<Statement>
<DatabaseName>testDB</DatabaseName>
<![CDATA[
{
"create": {
"object": {
"database":"testDB"
}
}
}
]]>
</Statement>
</Command>
<Properties />
</Execute>
In fact, you can also replace \" by ".