Skip to content

Instantly share code, notes, and snippets.

@faytranevozter
Last active February 25, 2021 12:21
Show Gist options
  • Save faytranevozter/1aa6371601e0eb06410442d735db337b to your computer and use it in GitHub Desktop.
Save faytranevozter/1aa6371601e0eb06410442d735db337b to your computer and use it in GitHub Desktop.
JSON searchable postman response test script
<input type="text" id="filter" value="$"><pre id="display"></pre><style>#filter{padding:10px;width:400px;font-family:monospace}#display{background-color:#ccc;border-radius:1rem;padding:10px;min-height:50px}.error{background-color:#ffcdd2 !important;color:#6f0404 !important}</style> <script src="https://unpkg.com/jsonpath@1.0.2/./jsonpath.js"></script> <script>pm.getData((err,val)=>{const json=val.response;const findJSON=()=>{try{const filtered=jsonpath.query(json,document.querySelector('#filter').value);document.querySelector('#display').classList.remove('error');document.querySelector('#display').innerHTML=JSON.stringify(filtered,null," ");}catch(err){document.querySelector('#display').classList.add('error');document.querySelector('#display').innerHTML=err.message;}};document.querySelector('#filter').addEventListener('keyup',findJSON);findJSON();})</script>
@faytranevozter
Copy link
Author

faytranevozter commented Feb 25, 2021

Full test script below

pm.visualizer.set(`<input type="text" id="filter" value="$"><pre id="display"></pre><style>#filter{padding:10px;width:400px;font-family:monospace}#display{background-color:#ccc;border-radius:1rem;padding:10px;min-height:50px}.error{background-color:#ffcdd2 !important;color:#6f0404 !important}</style> <script src="https://unpkg.com/jsonpath@1.0.2/./jsonpath.js"></script> <script>pm.getData((err,val)=>{const json=val.response;const findJSON=()=>{try{const filtered=jsonpath.query(json,document.querySelector('#filter').value);document.querySelector('#display').classList.remove('error');document.querySelector('#display').innerHTML=JSON.stringify(filtered,null," ");}catch(err){document.querySelector('#display').classList.add('error');document.querySelector('#display').innerHTML=err.message;}};document.querySelector('#filter').addEventListener('keyup',findJSON);findJSON();})</script>`, {response: pm.response.json()});

Just copy code above into your postman script

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