0

Input:

{
  "categories": {
    "1": {
      "name": "Books"
    },
    "2": {
      "name": "Games"
    }
  }
}

Spec:

[
  {
    "operation": "shift",
    "spec": {
      "categories": {
        "*": {
          "@": "categories"
        }
      }
    }
  }
]

Output (array of categories):

{
  "categories" : [ {
    "name" : "Books"
  }, {
    "name" : "Games"
  } ]
}

Another Input with just one element

{
  "categories": {
    "1": {
      "name": "Books"
    }
  }
}

Output:

{
  "categories" : {
    "name" : "Books"
  }
}

I expected the output to be a categories array containing just one element. Why does this spec not create an array when there is a single element?

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

1 Answers1

0

I managed this problem with following transformation:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "categories[#1]"
      }
    }
  }
]
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601