joelvh/json2json — pull request #9 by mikejpeters (2014-10-24 20:21:40+00:00)
Title: Add forceArray config option

Add `forceArray` config option that, when set to `true`, will wrap the node in an array if it is a map. Useful when transforming JSON that was converted from XML, in which case a node that may normally contain multiple items will be converted to a JSON map if it only contains a single item.

For example, an XML to JSON converter will typically convert the XML:

```xml

Belgian Waffles
$5.95

```

to the JSON:

```json
{
"breakfast_menu": {
"food": {
"name": "Belgian Waffles",
"price": "$5.95"
}
}
}
```

The `forceArray` config option can be used to rectify this:

```js
new json2json.ObjectTemplate({
path: 'breakfast_menu.food',
all: true,
forceArray: true
}).transform(json)
```

```[ { name: 'Belgian Waffles', price: '$5.95' } ]```