3

Assuming the structure of the json string does not change, is the order of a jsonpath match value result stable?

import jsonpath_ng

response = json.loads(response)

jsonpath_expression_name = jsonpath_ng.parse("$[forms][0][questionGroups][*][questions]..[name]")
match_name = [match.value for match in jsonpath_expression_name.find(response)]

jsonpath_expression_id = jsonpath_ng.parse("$[forms][0][questionGroups][*][questions]..[id]")
matches_id = [match.value for match in jsonpath_expression_id.find(response)]

survey_q_dict = { k:v for (k,v) in zip(matches_id, match_name)}

Thank you!

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Clay Campbell
  • 168
  • 13

0 Answers0