Library version: | 1.0.0 |
---|---|
Library scope: | global |
Named arguments: | supported |
Library for JSON validation. Based on: JSONSchema, JSONPath, JSONSelect.
jsonschema | https://pypi.python.org/pypi/jsonschema |
jsonpath-rw-ext | https://pypi.python.org/pypi/jsonpath-rw-ext |
objectpath | https://pypi.python.org/pypi/objectpath/ |
pyjsonselect | https://pypi.python.org/pypi/pyjsonselect |
json_example.json
{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } }
Settings | Value | ||
Library | JsonValidator | ||
Library | OperatingSystem | ||
Test Cases | Action | Argument | Argument |
Check element | ${json_example}= | OperatingSystem.Get File | ${CURDIR}${/}json_example.json |
Element should exist | ${json_example} | .author:contains("Evelyn Waugh") |
Keyword | Arguments | Documentation | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Element Should Exist | json_string, expr | Check the existence of one or more elements, matching JSONSelect expression. DEPRECATED JSON Select query language is outdated and not supported any more. Use other keywords of this library to query JSON. Args: json_string - JSON string; expr - JSONSelect expression; Raises: JsonValidatorError Example:
| ||||||||||||||||||||||||||||||||||||
Element Should Not Exist | json_string, expr | Check that one or more elements, matching JSONSelect expression, don't exist. DEPRECATED JSON Select query language is outdated and not supported any more. Use other keywords of this library to query JSON. Args: json_string - JSON string; expr - JSONSelect expression; Raises: JsonValidatorError | ||||||||||||||||||||||||||||||||||||
Get Elements | json_string, expr | Get list of elements from json_string, matching JSONPath expression. Args: json_string - JSON string; expr - JSONPath expression; Returns: List of found elements or Example:
=> [u'Nigel Rees', u'Evelyn Waugh', u'Herman Melville', u'J. R. R. Tolkien'] | ||||||||||||||||||||||||||||||||||||
Json To String | source | Serialize JSON structure into string. Args: source - JSON structure Returns: JSON string Raises: JsonValidatorError Example:
| ||||||||||||||||||||||||||||||||||||
Pretty Print Json | json_string | Return formatted JSON string json_string. Using method json.dumps with settings: indent=2, ensure_ascii=False. Args: json_string - JSON string. Returns: Formatted JSON string. Example:
=> { "a": 1, "foo": [ { "c": 3, "b": 2 }, { "e": 4, "d": "baz" } ] } | ||||||||||||||||||||||||||||||||||||
Select Elements | json_string, expr | Return list of elements from json_string, matching JSONSelect expression. DEPRECATED JSON Select query language is outdated and not supported any more. Use other keywords of this library to query JSON. Args: json_string - JSON string; expr - JSONSelect expression; Returns: List of found elements or Example:
=> 12.99 | ||||||||||||||||||||||||||||||||||||
Select Objects | json_string, expr | Return list of elements from json_string, matching ObjectPath expression. Args: json_string - JSON string; expr - ObjectPath expression; Returns: List of found elements. If no elements were found, empty list will be returned Example:
=> [12.99] | ||||||||||||||||||||||||||||||||||||
String To Json | source | Deserialize string into JSON structure. Args: source - JSON string Returns: JSON structure Raises: JsonValidatorError Example:
=> 8.95 | ||||||||||||||||||||||||||||||||||||
Update Json | json_string, expr, value, index=0 | Replace the value in the JSON string. Args: json_string - JSON string; expr - JSONPath expression for determining the value to be replaced; value - the value to be replaced with; index - index for selecting item within a match list, default value is 0; Returns: Changed JSON in dictionary format. Example:
| ||||||||||||||||||||||||||||||||||||
Validate Jsonschema | json_string, input_schema | Validate JSON according to schema. Args: json_string - JSON string; input_schema - schema in string format; Raises: JsonValidatorError Example:
| ||||||||||||||||||||||||||||||||||||
Validate Jsonschema From File | json_string, path_to_schema | Validate JSON according to schema, loaded from a file. Args: json_string - JSON string; path_to_schema - path to file with JSON schema; Raises: JsonValidatorError Example:
|