Is there a way to deal with a more complicated JSON structures?

Max Sinelnikov April 19, 2017

First of all, thank you guys for the excellent plugin.
I've just installed a trial version and I'm almost sure that this plugin is exactly what I was looking for.
I still have one question.
According to PocketQuery documentation my REST service has to return an array. But sometimes I want to load and render a more complicated structure.
For example, my REST API returns an object with two fields:

{
  paging: ..pagination data object..
  content: ..result array..
}

I can render a data table by specifying JSON Path as "$.content" or using a custom converter. But I can't access "paging" object to extract paging.totalCount value. I know there is a rawResult variable defined, but it seems that rawResult is typed as java.lang.Object, and it's imposible to cast this variable to something like Map from velocity context. Any suggestions?

1 answer

0 votes
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2017

Hi Max,

Thank you for your interest in PocketQuery! It's a very valid question! I'll try to explain from a more technical point of view: the way how PocketQuery deals with results after they were fetched is the specific data the array-of-objects style data structure that the results from your REST API should look like. When we developed 3.0, we were searching for a way to make this a convention, so we could handle all kinds of data sources (also: the results from SQL databases always look like this data structure using the libraries we use). So our decision was that also the results from REST APIs should be converted into this data structure. But the problem is that we can never know what the results from REST APIs will look like - the structure can be arbitrary.

That's why we came of with the idea of converters. The idea of a converter: it receives the raw results from the data source as input and returns the result in a format as we need it. So if you have your results in the format you describe, you'll have to write your own converter.

Converters look like this:

function convert(json) {

}

The json argument in that function is the json result retrieved from your data source using the given JSON Path ($.content) in your case. Now you need to parse this JSON string, convert it into an array-of-objects structure (with the column names as property keys) and return that structure.

For further information, please check our docs on converters.

Best, Felix

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events