JSON Deletion Service (com.ibi.agents.XDJsonDeleteAgent)

Syntax:

com.ibi.agents.XDJsonDeleteAgent

Description:

This service removes a field in a JSON object, or an item in a JSON array. This service requires a JSON input document. Any other type of document will return fail_operation.

The value is deleted in one or more parents selected by a JsonPath expression. Selecting more than one parent causes the value to be deleted in every parent.

The key determines which value is deleted within the parent. If the parent is an object, the key is the name of the field. After execution, the field is completely removed. If the parent is an array, the key is the index within the array counting from zero (0). After execution, the item at that index is removed and the array is compacted.

By default, the operation is successful even if the key is not found. The rationale is that the key does not have to be deleted, if it does not exist. This can happen when the JsonPath expression did not select any parents, in which case the output document is the input document unchanged. It can also happen if the field does not exist in an object, or the index is beyond the length of an array. In this case, that parent is not modified in the output, but the rest of the output document will reflect deletions in other selected parents.

Optionally, the service can return an error document and follow a failure edge when one or more keys do not exist.

Parameters:

The following table describes the parameters of the JSON Deletion service.

Parameter Name

Description

Parent Path

A JsonPath expression returning one or more parents where the JSON value will be deleted. A parent can be a JSON object or a JSON array.

Key

Determines which value is deleted in the parent. For a JSON object parent, this is the key in the map. For a JSON array parent, this is the index in the array.

Key Not Found

Determines the output when no parents are found, or a key is not found in one of the parents. Selecting Success will return successfully. Selecting Error Status will return an error status document with a failure.

Edges:

The following table describes the edges that are returned by the JSON Deletion service.

Line Edge

Description

success

Value was successfully inserted.

fail_parse

An iFL, JSON, or a JsonPath expression could not be evaluated.

fail_notfound

No parents were selected, or a key was not found in one of the parents, and Key Not Found is Error Status.

fail_operation

Operation could not be completed successfully.

Examples

Deleting the key k within parent $ in the JSON document {"k":"str","k1":1} produces {"k1":1}.

Deleting the key 1 within parent $.arr in the JSON document {"arr":[0,11,22]} produces {"arr":[0,22]}.

Deleting the key k within the multiple parents $.[*] in the JSON document [{"k":"a","k1":1},{"k":"b","k1":11}] produces [{"k1":1},{"k1":11}].

When Key Not Found is Success, deleting the non-existing key k within parent $ in the JSON document {"k1":1,"k2":2} returns the document unchanged.

When Key Not Found is Error Status, deleting the non-existing key k within parent $ in the JSON document {"k1":1,"k2":2} returns the following error document and the service follows the fail_notfound edge.

<eda><error timestamp="2019-07-10T20:58:30Z" code="6" stage="AGENT" source=""
parentpath="$" key="k" notfound="status">XD[FAIL] cause: 0 subcause: 0
message: Missing field k in JSON object</error></eda>