Skip to content

Add object collection mode to decomposition

gwn requested to merge (removed):master into master

Sometimes it is useful to have the nested collections in decomposed resultsets as an object instead of an array.

Keys will be set to the primary keys of the corresponding items.

My specific scenario involves diffing different versions of objects (generated via decomposition) using JSON patch tools. To get meaningful diffs; it is essential to have the nested collections as objects with unique keys.

I thought that implementing my own decomposition helper would be overkill when the one you already provide can easily be adapted to support this feature; and that this feature may be generic & useful enough to be considered to be included in Massive.js.

Objects are a kind of collection too after all; collection of key & value pairs.

What do you think?


This patch introduces an object flag to nested decomposition schemas, similar to the existing array flag. Setting object: true will generate an output like:

{
    "id": 1,
    "title": "lorem ipsum dolor sit amet",
    "nested": {
        1: {
            id: 1,
            title: "foo bar baz bar"
        },
        2: {
            id: 2,
            title: "love me two times baby"
        }
    }
}
Edited by gwn

Merge request reports