Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/159.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug when accessing a jmespath integer or float.
2 changes: 1 addition & 1 deletion jdiff/extract_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def extract_data_from_json(data: Union[Mapping, List], path: str = "*", exclude:
raise TypeError("JMSPath returned 'None'. Please, verify your JMSPath regex.")

# check for multi-nested lists
if any(isinstance(i, list) for i in values):
if isinstance(values, list) and any(isinstance(i, list) for i in values):
# process elements to check if lists should be flattened
for element in values:
for item in element:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_get_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,16 @@ def test_extract_data_from_json_with_ref_key_and_list_value():
value = extract_data_from_json(data=data, path="[*].[$id$,include_trusted_domains]")

assert value == expected_value, ASSERT_FAIL_MESSAGE.format(output=value, expected_output=expected_value)


def test_extract_data_from_json_with_int_or_float_values():
"""Verify that extract_data_from_json correctly handles ref-key paths when the extracted field value is an int or float."""
data = {"x": 5, "y": 0.75}

expected_value = 5
value = extract_data_from_json(data=data, path="x")
assert value == expected_value, ASSERT_FAIL_MESSAGE.format(output=value, expected_output=expected_value)

expected_value = 0.75
value = extract_data_from_json(data=data, path="y")
assert value == expected_value, ASSERT_FAIL_MESSAGE.format(output=value, expected_output=expected_value)
Loading