question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't filter on array of arrays

See original GitHub issue

Hello guys,

I have a JSON like this : { "_source": { "Asset": [ { "Ref": [ { "string": [ "1358420" ], "@field": "REF" } ], "ImageType": [ [ { "string": "Image", "@code": "ImageType-DAM_MTYP_IMAGE", "@field": "IMAGE_TYPE" } ], [ { "string": "Packshot", "@code": "ImageType-DAM_MTYP_3014", "@field": "IMAGE_TYPE" } ] ] }, { "Ref": [ { "string": [ "896_1" ], "@field": "REF" } ], "ImageType": [ [ { "string": "Product Photo", "@code": "ImageType-DAM_MTYP_3011", "@field": "IMAGE_TYPE" } ], [ { "string": "Packshot", "@code": "ImageType-DAM_MTYP_3014", "@field": "IMAGE_TYPE" } ] ] } ] } }

json

I have to filter the assets on Ref and ImageType code. I’m using this filter for the Ref : Filter refFilter = Filter.filter(where(“Ref[0].string[0]”).is(“1358420”)); parse(json).read(“_source.Asset[?]”, refFilter); This is working.

Now for the ImageType code : Filter imageTypeFilter = Filter.filter(where(“ImageType[0][0].@code”).is(“ImageType-DAM_MTYP_IMAGE”)); This is working.

However, Filter imageTypeFilter = Filter.filter(where(“ImageType[0][1].@code”).is(“ImageType-DAM_MTYP_3014”)); This doesn’t work. Can you tell me why please ? Is it a problem in my code or is there a bug ? Thank you in advance for your answer. I’m struggling with this for hours…

Regards

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
sbrooymanscommented, Feb 14, 2019

Done. Sorry I tried to simplify it at the maximum. The original one is more than 11000 lines !

0reactions
cmunillacommented, Apr 9, 2019

Regardless of the JsonPath implementation and limitations, in these cases the appropriate indexes are [1][0] and not [0][1] for what you are searching for.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to filter an array from all elements of another array
The code below is the simplest way to filter an array with respect to another array. Both arrays can have objects inside them...
Read more >
Array.prototype.filter() - JavaScript - MDN Web Docs
The filter() method creates a shallow copy of a portion of a given array, filtered down to just the elements from the given...
Read more >
Filtering arrays with TypeScript type guards - Spencer Miskoviak
Inevitably individual elements need to be found and filtered from this array. TypeScript can provide a layer of type-safety when working ...
Read more >
Filtering arrays - Amazon Athena - AWS Documentation
You can use the filter function on an ARRAY expression to create a new array that is the subset of the items in...
Read more >
array_filter - Manual - PHP
array_filter — Filters elements of an array using a callback function ... array_intersect() - Computes the intersection of arrays; array_map() - Applies the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found