Share this page

# lr_json_delete

Deletes the values in a JSON object that match the query.

int lr_json_delete( "JsonObject=<parameter name>", QueryString=<JSON query>", ["SelectAll=<Yes|No>",] ["NotFound=<Error|Continue>",] LAST );

Alphabetical Listing - C Language Utility Functions

## Arguments

Name | Comments
--- | ---
JsonObject | The name of an object created with lr_eval_json .
QueryString | The JSON query
NotFound | Optional. One of: Error - Script run is aborted and error message is sent. (Default) Continue - Script run continues. A warning message is sent.
SelectAll | Optional: If Yes, deletes all matches. If No, deletes first match. Default is No.
LAST | Required marker for the end of the argument list.

lr_json_delete deletes items from a JSON object that match the query.

This function is not recorded. You can insert it manually into your script.

## Return Values

The number of items deleted.

## Parameterization

Parameterization is not applicable to this function.

## Example

This script shows the usage of lr_json_delete.

Copy code

    TestDelete()
    {
        int i = 0;

        // See <MadCap:xref href="etc/lrFr_store_json.htm" xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd">File: store.json</MadCap:xref>
        lr_eval_json("Buffer/File=store.json",
                         "JsonObject=d_json_obj", LAST);

        lr_json_stringify("JsonObject=d_json_obj",
                          "OutputParam=d_result",
                         LAST);
        // 1 match
        i = lr_json_delete("JsonObject=d_json_obj",
                        "QueryString=$.store.name",
                         LAST);
        lr_json_stringify("JsonObject=d_json_obj",
                          "OutputParam=d_result",
                         LAST);
        if (i != 1)
            lr_error_message("lr_json_delete should return %d, but returns %d", 1, i);

        lr_save_string("$.store.books[*].isbn", "d_path_isbn");

        // 2 matches
        i = lr_json_delete("JsonObject=d_json_obj",
                        "QueryString={d_path_isbn}",
                        "SelectAll=Yes",
                         LAST);
        if (i != 2)
            lr_error_message("lr_json_delete should return %d, but returns %d", 2, i);

        lr_json_stringify("JsonObject=d_json_obj",
                          "OutputParam=d_result",
                         LAST);

        return 0;
    }

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: