Repository navigation
Minify JSON/XML #10574
Unanswered
lucasschonn
asked this question in
Ideas
Minify JSON/XML
#10574
Replies: 1 comment
|
There's no minify option yet as far as I can tell, but a pre-request script can do it, so you don't have to paste the body into VS Code every time: const { mode, raw } = insomnia.request.body;
if (mode === 'raw' && raw) {
let minified;
try {
minified = JSON.stringify(JSON.parse(raw));
} catch {
minified = raw.replace(/>\s+</g, '><').trim(); // XML
}
insomnia.request.body.update({ mode: 'raw', raw: minified });
}The body in the editor stays formatted; only what gets sent is minified, and the Content-Type stays the same. One thing to watch: if your JSON has template tags outside quotes (like |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Since there is a 'Beautify JSON/XML' option, it would be useful to have the reverse—'Minify JSON/XML'—given that some web services reject the payload if it is formatted; currently, I have to use the VS Code minify extension when this is required.
All reactions