如何使用 JSONata 附加嵌套在 JSON 对象内的数组

How to append an array nested inside JSON object using JSONata

我正在尝试使用 JSONata 在以下 JSON:

中的“选项”数组中附​​加一个额外的对象
{
  "description": "[IGNORE] Field used for testing",
  "displayOrder": 2,
  "fieldType": "select",
  "formField": true,
  "groupName": "excell_data",
  "label": "Dev Test Field [IGNORE]",
  "name": "dev_test_field",
  "options": [
    {
      "description": "Choice number one",
      "displayOrder": 1,
      "hidden": false,
      "label": "Option 1",
      "value": "1"
    },
    {
      "description": "Choice number two",
      "displayOrder": 2,
      "hidden": false,
      "label": "Option 2",
      "value": "2"
    },
    {
      "description": "Choice option three",
      "displayOrder": 3,
      "hidden": false,
      "label": "Option 3",
      "value": "3"
    }
  ],
  "type": "enumeration"
}

这样就变成了:

{
  "description": "[IGNORE] Field used for testing",
  "displayOrder": 2,
  "fieldType": "select",
  "formField": true,
  "groupName": "excell_data",
  "label": "Dev Test Field [IGNORE]",
  "name": "dev_test_field",
  "options": [
    {
      "description": "Choice number one",
      "displayOrder": 1,
      "hidden": false,
      "label": "Option 1",
      "value": "1"
    },
    {
      "description": "Choice number two",
      "displayOrder": 2,
      "hidden": false,
      "label": "Option 2",
      "value": "2"
    },
    {
      "description": "Choice option three",
      "displayOrder": 3,
      "hidden": false,
      "label": "Option 3",
      "value": "3"
    },
    {
      "description": "Choice number four",
      "displayOrder": 4,
      "hidden": false,
      "label": "Option 4",
      "value": 4
    }
  ],
  "type": "enumeration"
}

但是,当我尝试使用追加函数时,我很难 return 父 JSON 以及嵌套在其中的附加对象。

JSONata fiddler link 这里:https://try.jsonata.org/iv7zhPZcr

谁能指出我哪里出错了?

非常感谢。 乔纳森

使用变换运算符修改父对象中的选项对象:

$ ~> | $ | {
    "options": [options, {
        "description": "Choice number four",
        "displayOrder": 4,
        "hidden": false,
        "label": "Option 4",
        "value": 4
    }]
} | 

参见:https://try.jsonata.org/9RLURkd9l

https://docs.jsonata.org/other-operators#-------transform