Layer7 API Management

  • 1.  JSON Path Expression filter

    Posted Dec 18, 2017 12:00 AM

    Is there any support or documentation of JSON Path expression filter similar to that of XPath?

     

    JSONPath - XPath for JSON 



  • 2.  Re: JSON Path Expression filter

    Broadcom Employee
    Posted Dec 18, 2017 08:56 AM

    Hi,

     

    We do support JSON Path expressions as noted below. I am not sure of any more detailed docs, is there something in particular you are looking for?

     

    Evaluate JSON Path Expression Assertion - CA API Gateway - 9.2 - CA Technologies Documentation 

     

    Regards,

    Joe



  • 3.  Re: JSON Path Expression filter

    Posted Dec 20, 2017 04:15 AM

    Hi Joe,

     

    I'm looking for filtering in JSON Path expression.

     

    For example, in XPath the filtering of nodes is done via //book[price<10], what is the JSON Path equivalent for the assertion as the methods proposed by the link provided in the question does not work in the assertion.



  • 4.  Re: JSON Path Expression filter

    Broadcom Employee
    Posted Dec 20, 2017 08:45 AM

    Hi Shawn,

     

    Given the below sample JSON the equivalent JSON path expressions would be in this format noted at the bottom of this post. This sample was tested against a 9.2 Gateway. 

     

    Sample JSON

    { "store": {
    "book": [
    { "category": "reference",
    "author": "Nigel Rees",
    "title": "Sayings of the Century",
    "price": 8.95,
    "bool": true
    },
    { "category": "fiction",
    "author": "Evelyn Waugh",
    "title": "Sword of Honour",
    "price": 12.99,
    "number": -1
    },
    { "category": "fiction",
    "author": "Herman Melville",
    "title": "Moby Dick",
    "isbn": "0-553-21311-3",
    "price": 8.99,
    "bool": false,
    "number": -2.99
    },
    { "category": "fiction",
    "author": "J. R. R. Tolkien",
    "title": "The Lord of the Rings",
    "isbn": "0-395-19395-8",
    "price": 22.99,
    "number":0,
    "bool": true
    }
    ],
    "bicycle": {
    "color": "red",
    "price": 19.95,
    }
    }
    }

     

    JSON PATH

    $..book[?(@.price<=8.95)

    $..book[?(@.price>=8.95)

    $..book[?(@.price==8.95)

    $..book[?(@.price<>8.95)

     

     

     

    Hope this helps.

     

    Regards,

    Joe



  • 5.  Re: JSON Path Expression filter

    Posted Dec 21, 2017 05:02 AM

    Hi Joe,

     

    Thanks for the working example, was trying it out in the test tab, but does not seem to be working. Could you check if the expression filter is working for you in the test tab?



  • 6.  Re: JSON Path Expression filter
    Best Answer

    Broadcom Employee
    Posted Dec 22, 2017 11:09 AM

    Hi Shawn, 

     

    Sorry on the delay, I mistyped that in the text of my post but the screenshot was accurate. It should have read like this (I missed the closing bracket ']' ).

     

    $..book[?(@.price<=8.95)]


    $..book[?(@.price>=8.95)]


    $..book[?(@.price==8.95)]


    $..book[?(@.price<>8.95)]