Postman 去除json参数注释
将以下代码复制到 Postman 预请求脚本
// 去除json参数注释方法 GlobalJsonMinify = function (json) { var tokenizer = / "|(\/\*)|(\*\/)|(\/\/)|\n|\r|\[|]/g, in_string = false, in_multiline_comment = false, in_singleline_comment = false, tmp, tmp2, new_str = [], ns = 0, from = 0, lc, rc, prevFrom ; tokenizer.lastIndex = 0; while ( tmp = tokenizer.exec(json) ) { lc = RegExp.leftContext; rc = RegExp.rightContext; if (!in_multiline_comment && !in_singleline_comment) { tmp2 = lc.substring(from); if (!in_string) { tmp2 = tmp2.replace(/(\n|\r|\s)*/g," "); } new_str[ns++] = tmp2; } prevFrom = from; from = tokenizer.lastIndex; // found a " character, and we're not currently in // a comment? check for previous `\` escaping immediately // leftward adjacent to this match if (tmp[0] === "\"" && !in_multiline_comment && !in_singleline_comment) { // limit left-context matching to only go back // to the position of the last token match // // see: https://github.com/getify/JSON.minify/issues/64 lc.lastIndex = prevFrom; // perform leftward adjacent escaping match tmp2 = lc.match(/(\\)*$/); // start of string with ", or unescaped " character found to end string? if (!in_string || !tmp2 || (tmp2[0].length % 2) === 0) { in_string = !in_string; } from--; // include " character in next catch rc = json.substring(from); } else if (tmp[0] === " /*" && !in_string && !in_multiline_comment && !in_singleline_comment) { in_multiline_comment = true; } else if (tmp[0] === "*/ " && !in_string && in_multiline_comment && !in_singleline_comment) { in_multiline_comment = false; } else if (tmp[0] === " //" && !in_string && !in_multiline_comment && !in_singleline_comment) { in_singleline_comment = true ; } else if ((tmp[0] === "\n " || tmp[0] === " \r ") && !in_string && !in_multiline_comment && in_singleline_comment) { in_singleline_comment = false; } else if (!in_multiline_comment && !in_singleline_comment && !(/\n|\r|\s/.test(tmp[0]))) { new_str[ns++] = tmp[0]; } } new_str[ns++] = rc; return new_str.join(" "); }; pm.request.body.raw = GlobalJsonMinify(pm.request.body.raw) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)