Closed codedawi closed 3 years ago
Actually this works. We are just implementing this slightly differently that is probably causing the issue.
from jsonpath_ng import jsonpath, parse
jsonpath_expr_1 = parse("data.entity['com.hello.DS']")
# ALSO WORKS "data.entity.['com.hello.DS'].value"
jsonpath_input_1 = {
"data": {
"entity": {
"com.hello.DS": 123456
}
}
}
jsonpath_expr_2 = parse("data.entity['com.hello.DS'].value")
# ALSO WORKS "data.entity.['com.hello.DS'].value"
jsonpath_input_2 = {
"data": {
"entity": {
"com.hello.DS": {
"value": 123456
}
}
}
}
# Extracting values is easy
result_1 = [match.value for match in jsonpath_expr_1.find(jsonpath_input_1)]
result_2 = [match.value for match in jsonpath_expr_2.find(jsonpath_input_2)]
import json
print(json.dumps(result_1)) # -> 123456
print(json.dumps(result_2)) # -> 123456
We are attempting to use this package to parse values from a json payload that has keys with periods (
.
) in the name. It does not seem to support these and I provided two example use cases below. These are both technically validdict
and json objects.Input (Non-Nested):
Attempted JSONPath:
data.entity['com.hello.DS']
anddata.entity.['com.hello.DS']
Input (Nested):
Attempted JSONPath:
data.entity['com.hello.DS'].value
anddata.entity.['com.hello.DS'].value