Share this page

# lr_json_find

Returns the number of matches to a query in a JSON object.

int lr_json_find( "JsonObject=<parameter name>", "Value or ValueParam =<value>", "QueryString=<query>", ["SelectAll=<Yes|No>",] ["IgnoreCase=<Yes|No>",] ["UseRegExp=<Yes|No>",] ["NotFound=<Error|Continue>",] LAST );

Alphabetical Listing - C Language Utility Functions

## Arguments

Name | Comments
--- | ---
JsonObject | The name of the parameter that stores the handle of the JSON object created by lr_eval_json.
QueryString | The JSON query
Value | The value to find.
ValueParam | The name of a parameter containing the value to find
UseRegExp | Optional: If Yes, the Value is a regular expression. Default is No.
SelectAll | Optional: If Yes, returns the total number of matches. If No, stops after first match. Default is No.
IgnoreCase | Optional: If Yes, ignore case. Default is No.
NotFound | Optional. One of: Error - Script run is aborted and error message is sent. (Default) Continue - Script run continues. A warning message is sent.
LAST | Required marker for the end of the argument list.

lr_json_find runs the query on the JSON object and returns the number of matches.

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

## Return Values

The number of matches. If SelectAll = No, the number of matches is 0 or 1.

## Parameterization

Parameterization is not applicable to this function.

## Example

This script shows the usage of lr_json_find.

Copy code

    TestFind()
    {
        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>
        i = lr_eval_json("Buffer/File=store.json",
                         "JsonObject=f_json_obj", LAST);

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

        // Multi match with SelectAll=No
        i = lr_json_find("JsonObject=f_json_obj",
                        "Value=fiction",
                        "QueryString=$.store.books[*].category",
                         LAST);
        if (i != 1)
            lr_error_message("lr_json_find should return %d, but returns %d", 1, i);

        // Multi match with SelectAll=Yes
        i = lr_json_find("JsonObject=f_json_obj",
                        "Value=fiction",
                        "QueryString=$.store.books[*].category",
                        "SelectAll=Yes",
                         LAST);
        if (i != 3)
            lr_error_message("lr_json_find should return %d, but returns %d", 1, i);

        // Use RegExp

        lr_save_string("$..books[?(@.price>10)].author", "f_path_author");

        i = lr_json_find("JsonObject=f_json_obj",
                    "Value=.*Tolkien",
                    "QueryString={f_path_author}",
                    "UseRegExp=Yes",
                     LAST);

        if (i != 1)
            lr_error_message("lr_json_find should return %d, but returns %d", 1, i);

        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: