Parsing the keypath in WEBUI

Hi Team,

My Yang file:

container computers {

  list device-list {

    key "keyboardinfo";

    leaf keyboardinfo {
    
         type string;

     }
     leaf monitor;
     leaf printer;
   }
}

I have key leaf “keyboardinfo” datum in a list like below,

keyboard1-1/keyboard1
keyboard1-1/keyboard2
keyboard2-1/keyboard1
keyboard2-2/keyboard2

I need to filter based on the “keyboard1” or "keyboard2"string.

In get_schema api, I am trying to get the complete shema of computers and filtering is done in keypath based on regexp like below,

getSchema(th, '', '/computers:computer/computers:devices-list', 1, false).done(function(schema)

keypath : '/computers:computer/computers:devices-list[contains(resource,"/keyboard1")]';

But “/keyboard1” is unable to filter. Error is invalid key path. Because / is taken as another keypath parser.

But If I give,
keypath : '/computers:computer/computers:devices-list[contains(resource,"keyboard1")]';

I am able to get the result as,

keyboard1-1/keyboard1
keyboard1-1/keyboard2
keyboard2-1/keyboard1

But my intention to retieve the output as, 
keyboard1-1/keyboard1
keyboard2-1/keyboard1

Please provide your valuable suggestion on this.

Thanks,
Shanthini

Hi Shanthini,

I believe you want to use the JSON-RPC API “query” method instead of “get_schema”.

You set the xpath_expr parameter to something like /computers/device-list[contains(keyboardinfo, “/keyboard1”)]

Here is a curl tool example:
$ curl --cookie "sessionid_8008=sessX+w3eSWaYeivMj0r8vLKMw==;" -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "id": 1, "method": "query", "params": {"th": 1, "xpath_expr": "/computers/device-list[contains(keyboardinfo, \"/keyboard1\")]"}}' http://127.0.0.1:8008/jsonrpc

Result:

{"jsonrpc":"2.0","result":{"current_position":1,"total_number_of_results":2,"number_of_results":2,"number_of_elements_per_result":1,"results":[["keyboard1-1/keyboard1"],["keyboard2-1/keyboard1"]]},"id":1}

Thank you. I will check with query method.