jwadhams / json-logic

Build complex rules and serialize them to JSON
MIT License
116 stars 13 forks source link

Question - object from an array #43

Closed atusi86 closed 5 months ago

atusi86 commented 5 months ago

Hi all, Sorry if I'm not at the right place. I tried to find out a solution and read the whole supported operations list but I got stuck. Is there any way to get an object from an array and read a property from that object? I tried the example below on the playground but unfortunately it doesnt work.

Example data: { "application": { "customers": [ { "firstName": "John", "lastName": "Smith" } ] } }

Expected rule: {"var":"application.customers[0].firstName"}

Thank you in advance!

jwadhams commented 5 months ago

Yeah the dot syntax expects to work for both arrays and objects, so this rule should work: (Works in the JavaScript playground on jsonlogic.com for sure)

{"var":"application.customers.0.firstName"}
atusi86 commented 5 months ago

Thanks for your quick reply @jwadhams!