adriank / ObjectPath

The agile query language for semi-structured data
http://objectpath.org
MIT License
380 stars 93 forks source link

Recursion? #53

Closed khusseini closed 7 years ago

khusseini commented 7 years ago

Hey there, I was wondering if it was possible to do recursion of expressions?

Like so:

{
  attachments: $.items[ { title: @.name } ]
}

Which would result in:

[
  { title: somename },
  { title: somename2 }
]
adriank commented 7 years ago

How your input JSON looks like?

khusseini commented 7 years ago

For this case, something like

{
   items: [
       { name: somename, other: hello },
       { name: somename2, other: world }
   ]
}

then this expression

{
  attachments: $.items[ { title: @.name } ]
}

With this outcome

{
    attachments: [
        {title: somename}, 
        {title: somename2}
    ]
}
adriank commented 7 years ago

Unfortunately not. ObjectPath is a query language and your example is a schema conversion task. I thought about extending OP to make it possible, but I did not find enough time to do it.