bruno icon indicating copy to clipboard operation
bruno copied to clipboard

Prettify not working when “JSON body” contains variable #1553

Open ialloyd opened this issue 11 months ago • 2 comments

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.

ialloyd avatar Mar 14 '24 10:03 ialloyd

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.

asonkeri avatar Mar 17 '24 13:03 asonkeri

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.

ialloyd avatar Mar 17 '24 15:03 ialloyd