json-rules-engine icon indicating copy to clipboard operation
json-rules-engine copied to clipboard

How to handle array of objects?

Open ChhaviPoddar opened this issue 8 months ago • 1 comments

Usecase: Is there any equipment with type embroidery and setting speed 250?

Fact:

const facts = {
	equipmentList: [
		{ type: 'embroidery', setting: { speed: 250 } },
		{ type: 'sewing', setting: { speed: 150 } },
	],
	substrate: { color: { hexcode: '#FFFFFF' } },
	Size: 'S',
};

// the following IS NOT working as expected. no matter what 'setting.speed' I give, I am getting true for the condition

{
  "all": [
    {
      "fact": "equipmentList",
      "path": "$[?(@.type == 'sewing' && @.setting.speed == 250)]",
      "operator": "notEqual",
      "value": []
    },
  ]
}

Does the package support this kind of a usecase?

ChhaviPoddar avatar Jun 17 '25 16:06 ChhaviPoddar

the "notEqual" operator will not do a deep comparison of arrays. I would suggest creating a custom operator to handle that, something like "isEmpty" and "isNotEmpty"

chris-pardy avatar Jun 17 '25 16:06 chris-pardy