1

How do I query for a particular BusStopCode from within a JSON object in a JSON array

 "value": [
        {
            "BusStopCode": "01012",
            "RoadName": "Victoria St",
            "Description": "Hotel Grand Pacific",
            "Latitude": 1.29684825487647,
            "Longitude": 103.85253591654006
        },
        {
            "BusStopCode": "01013",
            "RoadName": "Victoria St",
            "Description": "St. Joseph's Ch",
            "Latitude": 1.29770970610083,
            "Longitude": 103.8532247463225
        },
       

for example if I want to find only the first object then the bus stop code I would query is 01012

my current URL query request looks like this- http://transport/dataservice/BusStops?BusStopCode=01012

here http://transport/dataservice/BusStops is my URL

and ?BusStopCode=01012 is my path

2 Answers2

0

tl;dr: You can't unless they implemenet it on the server side.

Postman is only the client side.

When you are sending a URL - the server reads it and have an implementation for this specific url / url + parameters in our case.

If the server have an implementation for something like http://transport/dataservice/BusStops?BusStopCode=01012 They should expose it to you. You can't guess what is their API.

ALUFTW
  • 1,914
  • 13
  • 24
0

You can filter your response data using JSONpath Visualizer in Postman.

To enable the Visualizer, please paste the following code in the Test section of Postman where you are creating your request.

let template = `
<html>
<head>
    <script src="https://cdn.jsdelivr.net/npm/jsonpath@1.0.2/jsonpath.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
</head>
<body>
    <div>
      <div>
        <input id="filter" style="width:450px;" type="text" placeholder="Example query: $..name.first">
      </div>
      <div>
        <button id="resetButton" style="background-color:red;color:white;">Reset</button>
        <input id="showErrors" type="checkbox" value="1"/>
        <span class="item-text" style="font-family:courier;">Show Evaluation Errors</span>
      </div>
      <div id="errors" style="font-family:courier;color:red;display:none;"></div>
      <div>
        <p id="content" style="font-family:courier;color:green;font-size:18px;"></p>
      </div>
    </div>
</body>
</html>

<script>
pm.getData( (error, value) => { 
    const extractedData = jsonpath.query(value, '$');
    
    $(function() {
        $('#filter').keyup(function() {
            try {
                let filteredData = jsonpath.query(extractedData, $(this).val());
                $("#content, #errors").empty();
                $("#content").append("<pre><code>" + JSON.stringify(filteredData, null, 4) + "</code></pre>");
            } catch (err) {
                console.info(err);
                $("#errors").empty();
                $("#errors").append("<pre><code>" + err + "</code></pre>");
            }
        });
    });
    
    $( "#resetButton" ).click(function() {
        $("#content, #errors").empty();
        $("#filter").val('');
        $("#content").append("<pre><code>" + JSON.stringify(extractedData, null, 4) + "</code></pre>");
    })
})

$(function() {
  $("#showErrors").on("click",function() {
    $("#errors").toggle(this.checked);
  });
});
</script>`

pm.visualizer.set(template, pm.response.json())

Here is the example.

enter image description here

Sample data is also provided for better understanding.

enter image description here

Muhammad Tariq
  • 3,318
  • 5
  • 38
  • 42