Package tlib :: Package base :: Module JsonHelper :: Class JsonHelper |
[hide private]
[frames] | no frames]

# Class JsonHelper

source code

    object --+
             |
            JsonHelper

Functions for modifying and validating JSON data

Instance Methods | [hide private]
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__init__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Static Methods | [hide private]
assert_json_equals(json1, json2, ignore_order=True, exclude_keys=`[``]`) Compares two JSON values | source code
_validate_json_ignoring_order(json1, json2, exclude_keys) Compares two JSON values, ignoring position of keys | source code
_validate_json_with_order(json1, json2, exclude_keys=`[``]`) Compares two JSON values, taking into account key order If json1 or json2 are strings, it must be a valid JSON string | source code
remove_keys(data, keys, top_level=True) Takes a dictionary or a list and removes keys specified by 'keys' parameter | source code
_remove_key(data, key, top_level=True) Takes a dictionary or a list and removes keys specified by 'keys' parameter | source code
get_elements(data, json_path) " Applies a JSON path to a JSON string and returns the resulting node | source code

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### assert_json_equals(json1, json2, ignore_order=True, exclude_keys=`[``]`) Static Method | source code
Compares two JSON values If parameter validate_order is True, position of keys is taken into account during validation If json1 or json2 are strings, it must be a valid JSON string Parameters: `json1` (str, dict) - String or dictionary to compare `json2` (str, dict) - String or dictionary to compare `ignore_order` (bool) - If true, order of keys is not validated `exclude_keys` (list) - Keys to exclude from comparison, in the format 'key2.key3[2].key1' Raises: `AssertionError` - JSON values doesn't match

### _validate_json_ignoring_order(json1, json2, exclude_keys) Static Method | source code
Compares two JSON values, ignoring position of keys If json1 or json2 are strings, it must be a valid JSON string Parameters: `json1` (str, dict) - String or dictionary to compare `json2` (str, dict) - String or dictionary to compare Raises: `AssertionError` - JSON values doesn't match

### _validate_json_with_order(json1, json2, exclude_keys=`[``]`) Static Method | source code
Compares two JSON values, taking into account key order If json1 or json2 are strings, it must be a valid JSON string Parameters: `json1` (str) - String to compare `json2` (str) - String to compare `exclude_keys` (list) - Keys to exclude from comparison, in the format 'key2.key3[2].key1' Raises: `AssertionError` - JSON values doesn't match

### remove_keys(data, keys, top_level=True) Static Method | source code
Takes a dictionary or a list and removes keys specified by 'keys' parameter Parameters: `data` (dictionary, OrderedDict) - dictionary or OrderedDict that will be modified. Object is replaced in place `keys` (list) - array indicating the path to remove. e.g. ['businessHours.headings[2]', 'businessHours.values.name']

### _remove_key(data, key, top_level=True) Static Method | source code
Takes a dictionary or a list and removes keys specified by 'keys' parameter Parameters: `data` (dictionary, OrderedDict) - dictionary or OrderedDict that will be modified. Object is replaced in place `key` (list) - array indicating the path to remove. e.g. ['businessHours', 'headings[2]']

### get_elements(data, json_path) Static Method | source code
" Applies a JSON path to a JSON string and returns the resulting node Parameters: `data` (str, dict)