Last active
February 25, 2021 12:21
-
-
Save faytranevozter/1aa6371601e0eb06410442d735db337b to your computer and use it in GitHub Desktop.
JSON searchable postman response test script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full test script below
Just copy code above into your postman script