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.

How to check for the length property with JsonLogic

See original GitHub issue

Hi, Sorry for coming back with another question please. My bad.

Here is my use case. I have a JSON obejct. I am using json-logic-fs to apply the query formatted as jsonlogic against my object. So far it works with the text fields.

What I also want to do is filter out the items which dont have children items inside . For example please see the following json object

{
 "name" : "Category of the post",
"posts": [ {"id" : 1 , "title" : "my first post"}]
},
{
 "name" : "Another post category",
"posts": []
}

I have the current fields set up as such

const fields = [
  { name: 'name', label: 'Category Name' },
  {
    name: 'posts',
    label: 'Has posts',
    valueEditorType: 'checkbox',
  },
];

What I would really like to do is to generate a query that will filter out categories which do not have any post, i.e categories which have posts field length is 0, will be filtered out.

The existing default operators wont help, I presume as I cannot use them to check for the length of an array.

Is there a way I can create a length operator and use it to filter categories which have the posts length as 0.

Sorry for a lengthy question.

Thanks once again for your time and patience.

With Regards Gagan

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakeboone02commented, Dec 12, 2022

I don’t know about “very popular” but thank you for the kind words!

1reaction
gj1118commented, Dec 12, 2022

You are godsend… Thanks a lot … it worked perfectly. Thank you once again. Much much appreciated. This is the first time, I am seeing such kind of support from the author of a very popular component. thanks once again. ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supported Operations - JsonLogic
Most JsonLogic rules operate on data supplied at run-time. Typically this data is an object, in which case the argument to var is...
Read more >
Add a "length" operation. · Issue #4 · jwadhams/json-logic
For strings, returns their length in characters. (Note there can be oddities in a language's string length calculation, like JavaScript's ...
Read more >
Get the property's array length in JSON response in Logic Apps
In relation to your example, I can see it's a length of one just by looking at it. This is the expression you...
Read more >
src/utils/jsonlogic/operators.js | formiojs
// Use only immutable useful functions from Lodash. · export const lodashOperators = [ · // Array · 'chunk', · 'compact', · 'concat',...
Read more >
Length of a json array - Power Platform Community - Microsoft
You could use the length() of workflow definition language to get ... I have made a test on my side and I have...
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