bruno
bruno copied to clipboard
Prettify not working when “JSON body” contains variable #1553
This PR enhances the JSON “Prettify” functionality to handle variables within the JSON body. The function now replaces variables with unique dummy values for prettification and then restores them, ensuring correct parsing and formatting of the JSON body.
This works fine with unquoted variables e.g. "hello": {{var}}
but fails when variables are inside quotes like "hello": "{{var}}"
. The quoted variable case gets turned into "hello": ""dummyValue0""
which json-bigint fails to parse as it is not valid JSON.
Seems that jsonc-parser
, as used in #1831, would be able to properly format even this double quoted value.
This fix handles the "Prettify" functionality for variables inside quotes. It uses a regex to match both quoted and unquoted variables, replaces them with dummy values, and then restores the original variables after prettifying the JSON.