Override One Array Element
+ and replace treat an array as a whole. Sometimes you need to reach INTO one existing
element and add fields to it. The real case: the Creative Library's Items.json has a
Children array of categories, and you want to add SubCategories to the stock Tools
category without disturbing the other six categories.
Goal
- Add a
SubCategorieslist to the existing{ "Id": "Tools" }element. - Leave
Weapons,Armors,Foods,Potions,Recipes,Ingredientsand theToolselement's ownName/Iconexactly as they are.
The Asset
Server/Item/Category/CreativeLibrary/Items.json
Without an element-targeting operator your only options are replace (restate every element) or append (a new sibling category in its own tab, not under Tools).
{
"Icon": "Icons/ItemCategories/Items.png",
"Order": 2,
"Children": [
{
"Id": "Tools", // the ONE element you want to extend
"Name": "server.ui.itemcategory.tools",
"Icon": "Icons/ItemCategories/Items-Tools.png"
},
{
"Id": "Weapons",
"Name": "server.ui.itemcategory.weapons",
"Icon": "Icons/ItemCategories/Items-Weapons.png"
},
{
"Id": "Armors",
"Name": "server.ui.itemcategory.armors",
"Icon": "Icons/ItemCategories/Items-Armor.png"
},
{
"Id": "Foods",
"Name": "server.ui.itemcategory.foods",
"Icon": "Icons/ItemCategories/Items-Food.png"
},
{
"Id": "Potions",
"Name": "server.ui.itemcategory.potions",
"Icon": "Icons/ItemCategories/Items-Potion.png"
},
{
"Id": "Recipes",
"Name": "server.ui.itemcategory.recipes",
"Icon": "Icons/ItemCategories/Items-Recipe.png"
},
{
"Id": "Ingredients",
"Name": "server.ui.itemcategory.ingredients",
"Icon": "Icons/ItemCategories/Items-Ingredients.png"
}
]
}
The patch
Path: Server/Item/Category/CreativeLibrary/Items.patch
{
"Children+": [
{
"$Match": "Id",
"Id": "Tools",
"SubCategories+": [
{ "Id": "Staffs", "Name": "server.ui.itemcategory.subcategory.staffs.name", "Order": 100 }
]
}
]
}
Children~ opts the array into element merging. $Match: "Id" finds the element whose Id
is Tools. The rest of the object merges into it, and the nested SubCategories+ appends
(creating the array, since Tools had none).
After
- The
Toolselement now has aSubCategoriesarray with yourStaffsentry. Toolskeeps itsNameandIcon. Every sibling category is untouched.$Matchis stripped and never appears in the merged asset.
{
"Id": "Tools",
"Name": "server.ui.itemcategory.tools",
"Icon": "Icons/ItemCategories/Items-Tools.png",
"SubCategories": [
{ "Id": "Staffs", "Name": "server.ui.itemcategory.subcategory.staffs.name", "Order": 100 }
]
}
Targeting by position instead
Not every array is keyed by a field. When there is nothing to match on, drop $Match and let
~ align by position. The patch element at each index merges into the base element at the
same index, and an empty {} merges nothing, so it skips a slot:
{ "SomeList~": [ {}, { "Enabled": false } ] }
This leaves index 0 alone and sets Enabled on index 1.
Notes
~is the element-merge operator;$Matchis an optional locator inside it (and inside+). There is no implicitIdmatching: matching happens only where you write$Match.- On a
$Matchmiss the suffix decides the fallback:~merges at the index,+appends (upsert), a bare key does nothing. Pair$Matchwith~or+when you want a defined fallback. SubCategories+inside the matched element shows that operators compose to any depth. See the syntax reference for the full ruleset.- A plain array with no
$Matchand no~/+still replaces wholesale, exactly as before.
