Inist-CNRS / node-jbj

Like XSL/XML but for JSON.
http://Inist-CNRS.github.io/jbj-playground/
13 stars 3 forks source link

Add a "array2object" action #11

Closed parmentf closed 9 years ago

parmentf commented 9 years ago

When you have an array containing elements of _id and value (no random example, this is what castorjs operators return), you may need to transform them to one object where _ids are property names and values are their values.

Ex:

[
{
    "_id": "2007",
    "value": 538
},
{
    "_id": "2008",
    "value": 577
},
{
    "_id": "2009",
    "value": 611
}
]

should be transformed into:

{
  "2007": 538,
  "2008": 377,
  "2009": 611
}

That way, you can access the 2008 value using getPropertyVar.

So, maybe the array2object action should have [ "_id", "value" ] as a default parameter (when the parameter is not an array).