Re #132 - Make a list of the JSONpath results instead of using only the first value

pull/138/head
dgtlmoon 3 years ago
parent dad48402f1
commit 83daa6f630

@ -97,18 +97,20 @@ class perform_site_check():
from jsonpath_ng import jsonpath, parse from jsonpath_ng import jsonpath, parse
json_data = json.loads(html) json_data = json.loads(html)
jsonpath_expression = parse(css_filter_rule.replace('json:','')) jsonpath_expression = parse(css_filter_rule.replace('json:', ''))
match = jsonpath_expression.find(json_data) match = jsonpath_expression.find(json_data)
if match: s = []
# @todo isnt there a better way to say this?
if type(match[0].value) == int or type(match[0].value) == str or type(match[0].value) == float: # More than one result, we will return it as a JSON list.
# A single string, just use that as a string if len(match) > 1:
# Be sure it becomes str for i in match:
stripped_text_from_html = str(match[0].value) s.append(i.value)
else:
# JSON encoded struct as str # Single value, use just the value, as it could be later used in a token in notifications.
stripped_text_from_html = json.dumps(match[0].value, indent=4) if len(match) == 1:
s = match[0].value
stripped_text_from_html = json.dumps(s, indent=4)
is_html = False is_html = False
else: else:

Loading…
Cancel
Save