Layer 7 API Management

Expand all | Collapse all

pagination for slicing required array

Jump to Best Answer
  • 1.  pagination for slicing required array

    Posted 11-07-2017 04:35 AM

    Hi, please share me the jsonpath expression to get slice of an array for pagination. I am using evaluate json path assertion and tried giving [start:end] but could not proceed, where in [:end] was working fine for 0 to end filtering. below is the sample

    input:

     

    [        { "category": "reference",         "author": "Nigel Rees",         "title": "Sayings of the Century",         "price": 8.95       },       { "category": "fiction",         "author": "Evelyn Waugh",         "title": "Sword of Honour",         "price": 12.99       },       { "category": "fiction",         "author": "Herman Melville",         "title": "Moby Dick",         "isbn": "0-553-21311-3",         "price": 8.99       },       { "category": "fiction",         "author": "J. R. R. Tolkien",         "title": "The Lord of the Rings",         "isbn": "0-395-19395-8",         "price": 22.99       },
    { "category": "fiction",         "author": "J. R. R. Tolkien",         "title": "The Lord of the Rings",         "isbn": "0-395-19395-8",         "price": 22.99       }
    ]


  • 2.  Re: pagination for slicing required array

    Posted 11-08-2017 01:28 PM

    Just include a dot or period in the JSON Expression as shown to get the array.

     

     

    Hope this helps.



  • 3.  Re: pagination for slicing required array

    Posted 11-09-2017 12:36 AM

    If i want to slice out particular values from array, say 3 to 5, how will this work? 



  • 4.  Re: pagination for slicing required array

     
    Posted 11-09-2017 04:38 AM

    Hi, have you tried:

     

    $.[3:5]

     

    /Mikael



  • 5.  Re: pagination for slicing required array

    Posted 11-09-2017 04:51 AM

    Yes , I did and its not working, its giving " For input string: "3:5"" when tested



  • 6.  Re: pagination for slicing required array

     
    Posted 11-09-2017 07:05 AM

    Hi again. I see. I guess that the library used for the assertion does not currently support that specific slicing syntax.



  • 7.  Re: pagination for slicing required array
    Best Answer

    Posted 11-09-2017 10:24 AM

    It looks like it supports a start or end for slicing but not both