def select_elements(self, json_string, expr):
        """
        Return list of elements from _json_string_, matching [ http://jsonselect.org/ | JSONSelect] expression.

        *DEPRECATED* JSON Select query language is outdated and not supported any more.
        Use other keywords of this library to query JSON.

        *Args:*\n
        _json_string_ - JSON string;\n
        _expr_ - JSONSelect expression;

        *Returns:*\n
        List of found elements or ``None`` if no elements were found

        *Example:*\n
        | *Settings* | *Value* |
        | Library    | JsonValidator |
        | Library    | OperatingSystem |
        | *Test Cases* | *Action* | *Argument* | *Argument* |
        | Select json elements | ${json_example}=   | OperatingSystem.Get File |   ${CURDIR}${/}json_example.json |
        |                      |  ${json_elements}= | Select elements  |  ${json_example}  |  .author:contains("Evelyn Waugh")~.price |
        =>\n
        | 12.99
        """
        load_input_json = self.string_to_json(json_string)
        # parsing jsonselect
        match = jsonselect.match(sel=expr, obj=load_input_json)
        ret = list(match)
        return ret if ret else None
Esempio n. 2
0
def apply_selector(objs, selector):
    '''Returns a list of objects which match the selector in any of objs.'''
    out = []
    for obj in objs:
        timer.log('Applying selector: %s' % selector)
        out += list(jsonselect.match(selector, objs))
        timer.log('done applying selector')
    return out
Esempio n. 3
0
File: jss.py Progetto: danvk/jss
def apply_selector(objs, selector):
    '''Returns a list of objects which match the selector in any of objs.'''
    out = []
    for obj in objs:
        timer.log('Applying selector: %s' % selector)
        out += list(jsonselect.match(selector, objs))
        timer.log('done applying selector')
    return out
Esempio n. 4
0
 def find_by(cls, mode, obj, path):
     if mode == "jsonpointer":
         return jsonpointer.resolve_pointer(obj, path)
     elif mode == "jsonpath":
         return jsonpath.jsonpath(obj, path)
     elif pyjq is not None and mode == "jq":
         return pyjq.all(path, obj)
     elif jsonselect is not None and mode == "jsonselect":
         return list(jsonselect.match(path, obj))
     return None
Esempio n. 5
0
def selector_to_ids(selector, obj, mode):
    def bail_on_match(obj, matches):
        return matches

    bail_fn = None
    if mode == DELETE:
        # There's no point in continuing a search below a node which will be
        # marked for deletion.
        bail_fn = bail_on_match

    matches = jsonselect.match(selector, obj, bailout_fn=bail_fn)
    return [id(node) for node in matches]
Esempio n. 6
0
File: jss.py Progetto: danvk/jss
def selector_to_ids(selector, obj, mode):
    def bail_on_match(obj, matches):
        return matches

    bail_fn = None
    if mode == DELETE:
        # There's no point in continuing a search below a node which will be
        # marked for deletion.
        bail_fn = bail_on_match

    matches = jsonselect.match(selector, obj, bailout_fn=bail_fn)
    return [id(node) for node in matches]