Share this page

# lr_json_get_values

Gets values from a path in a JSON object.

## C Language

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

Example | Parameter 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.
ValueParam | The name of a parameter to store the data found.
SelectAll | Optional: If Yes, finds all matches. If No, stops after first match. 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_get_values finds the data in the nodes that match the query and stores the data in the ValueParam parameter.

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

## Return Values

The number of matches.

## Parameterization

Parameterization is not applicable to this function.

## Example

This script shows the usage of lr_json_get_values.

    TestGetValues()
    {
    	int i;

    	// See Example: Data file: store.json
    	i = lr_eval_json("Buffer/File=store.json",
    	                 "JsonObject=s_json_obj", LAST);

    	i = lr_json_get_values("JsonObject=s_json_obj",
                    "ValueParam=s_new_storename",
                    "QueryString=$.store.name",
                     LAST);

    	// Multi match with SelectAll=Yes
    	lr_save_string("\"1111\"", "s_isbn_1");
    	lr_save_string("\"2222\"", "s_isbn_2");
    	lr_save_string("2", "s_isbn_count");

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

    	i = lr_json_set_values("JsonObject=s_json_obj",
    	                "ValueParam=s_isbn",
    	                "QueryString={s_path_isbn}",
    	                "SelectAll=Yes",
    	                 LAST);

    	i = lr_json_get_values("JsonObject=s_json_obj",
                    "ValueParam=s_new_isbn",
                    "QueryString={s_path_isbn}",
    	            "SelectAll=Yes",
                     LAST);

    	return 0;
    }

TestGetValues.c(11): Notify: Saving Parameter "s_new_storename = Black Books".

TestGetValues.c(31): Notify: Parameter Substitution: parameter "s_path_isbn" = "$.store.books[*].isbn"

TestGetValues.c(31): Notify: Saving Parameter "s_new_isbn_1 = 1111".

TestGetValues.c(31): Notify: Saving Parameter "s_new_isbn_2 = 2222".

TestGetValues.c(31): Notify: Saving Parameter "s_new_isbn_Count = 2".

TestGetValues.c(31): lr_json_get_values succeed, 2 matches

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