This is an extremely useful contribution and should be included in the standard library. One example I can provide where
it's useful is for the modification of attributes of an ECS Task Definition JSON (e.g. the envoy container) in the snippet below.
{
"containerDefinitions": [
{
"dockerLabels": {
"SERVICE_80_NAME": "someService-api-http",
"SERVICE_80_TAGS": "service=someService-api-http"
},
"environment": [
{
"name": "DEST_DB",
"value": "db.service.consul:27000"
}
],
"essential": true,
"image": "someRepo/someServiced:0.4.2",
"links": [
"envoy:db.service.consul"
],
"memory": 218,
"mountPoints": [ ],
"name": "someService",
"portMappings": [
{
"containerPort": 80,
"hostPort": 0,
"protocol": "tcp"
}
]
},
{
"dockerLabels": {
"SERVICE_9901_NAME": "envoy",
"SERVICE_9901_TAGS": "service=someService-api-http"
},
"environment": [
...
],
"essential": true,
"image": "someRepo/mongoproxy-envoy:versio",
"memory": 100,
"name": "envoy",
"portMappings": [
{
"containerPort": 9901,
"hostPort": 0,
"protocol": "tcp"
}
],
"volumesFrom": [ ]
}
],
"family": "someService-someENV",
"placementConstraints": [ ],
"volumes": [ ]
}
Related: It would also be useful to have functions to test existence of deeply nested fields as well as retrieve deeply nested values including those nested in objects in arrays nested within objects -- for example, if I wanted to obtain the value of the
envoy container or to determine if the envoy container exists given the json above. The following does not cover the array case, but does not require nested std.objectHas statements. (please let me know if there's a better way to do this in jsonet -- it's possible
via the jsonPath query $.containerDefinitions[?(@.name=='envoy'] if we had something similar then perhaps we could perform the query, patch the object, and subsequently patch the original object)