0

I have a JSON like below and need to search the path 'root['quiz']['maths']['1']'. How is this possible?

My original JSON below:

 {
   "dictionary_item_added":{
      "root['quiz']['maths']['Corozno']":{
         "question":"5 + 7 = ?",
         "options":[
            "10",
            "11",
            "12",
            "13"
         ],
         "answer":"12"
      },
      "root['quiz']['maths']['1']":{
         "question":"12 - 8 = ?",
         "optio8ns":[
            "1",
            "20",
            "3",
            "4"
         ],
         "answer":"4"
      }
   },
   }
}
dreftymac
  • 31,404
  • 26
  • 119
  • 182
Anup
  • 39
  • 6
  • 1
    have you tried `["1"]["question"]`? – Anwarvic Jun 25 '20 at 16:59
  • 1
    Do you have that as a dictionary in python, or as a json file / string? – Roy2012 Jun 25 '20 at 17:00
  • its as a json file – Anup Jun 25 '20 at 17:08
  • get this error: ParseError: Expecting: ['quoted_identifier', 'unquoted_identifier', 'lbracket', 'lbrace'], got: number: Parse error at column 11, token "1" (NUMBER), for expression: "quiz.maths.1" – Anup Jun 25 '20 at 17:14
  • What code gives you that error? As far as JSON is concerned, the key is an opaque string. As far as JMESPath is concerned, it's not clear what document those keys as path expressions refer to. – chepner Jun 25 '20 at 17:16
  • My code: json_2 = json.load(open(r'D:\DATA\json_2.json','r')) #print(json_2) print(jmespath.search("quiz.maths.1", json_2)) – Anup Jun 25 '20 at 17:19
  • I was able to resolve the issue, missed quotes: print(jmespath.search('quiz.maths."1"', json_2)) – Anup Jun 25 '20 at 17:34

1 Answers1

0

I was able to resolve the issue, need to enclose numbers quotes: print(jmespath.search('quiz.maths."1"', json_2))

Anup
  • 39
  • 6