Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ialloyd
Copy link
Contributor

@ialloyd ialloyd commented Mar 14, 2024

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.

@asonkeri
Copy link
Contributor

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.

@ialloyd
Copy link
Contributor Author

ialloyd commented Mar 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants