#895·expr

Add new builtin for merging maps

Author: dnbsdCreated Dec 31, 2025Updated Mar 19, 2026
Labelsfeature

Expr currently does not have a builtin for merging maps. Adding a new builtin would be useful to merge maps but also to modify nested fields.

For instance:

javascript
/*
Env:
{
  "data":{
    "status": 0,
    "rows": 32,
    "signing_keys":[
      "key1",
      "key2"
    ]
  }
}
*/

merge($env["data"], {signing_keys: concat($env["data"]["signing_keys"], ["another"])})

/*
Output:
{
  "data":{
    "status": 0,
    "rows": 32,
    "signing_keys":[
      "key1",
      "key2",
      "another"
    ]
  }
}
*/

As for the name, "merge" seems natural but I would also consider using "copy" (as used in Go's maps package). Other possibility is to modify "concat" to support both arrays and maps.