Delete a JSON's Item
Deletes a specified key from a JSON object.
Overview
This procedure deletes a specified key from a JSON object. The field is permanently removed from the JSON structure. If the specified key does not exist in the JSON, the operation completes successfully without error (in the new JSON implementation). The procedure supports both simple field names and nested paths using dot notation.
Input
json
json
The JSON object from which the key will be deleted
Yes
N/A
thing
string
The key to be deleted from the JSON object
Yes
N/A
Output
json
The updated JSON object after the specified key has been deleted
Examples
1. Deleting a simple field
This example deletes the "username" field from the JSON object.
get the json
delete the json's username2. Deleting a field and verifying the result
This example deletes the "TermsCode" field and shows the resulting JSON object would be: {"Description": "0.5% 10 NET 45"}
the term is "{\"TermsCode\": \"38\", \"Description\": \"0.5% 10 NET 45\"}"
get the term as a json
the term is a json
delete the term's TermsCode
the term3. Deleting a non-existent field (safe operation)
This example demonstrates that deleting a non-existent field does not cause an error and leaves the JSON unchanged at {"Description": "0.5% 10 NET 45"}.
delete the term's mybadfield
the term4. Deleting nested fields using dot notation
This example shows deleting a nested field using dot notation. For a JSON like {"b": {"c": 1, "d": {"e": [1, 2]}}}, this would remove the entire "d" object.
delete the foo's b.d5. Deleting fields from array elements
This example demonstrates deleting fields from specific elements in an array using ordinals. For a JSON with an "objects" array, this removes the "b" field from the second object and the "c" field from the last object.
delete the foo's second objects.b
delete the foo's last objects.c6. Deleting from nested structures
This example shows deleting fields from nested array structures. The second command demonstrates that deleting a non-existent field ("nowhere") does not cause an error.
delete the foo's third val.noteverywhere
delete the foo's first val.nowhereLast updated
Was this helpful?
