-2

How do I differentiate and parse data from strings like this to json objects:

"[{"months": 12, "product": "car"}, {"months": "12", "product": "bike"}]"

"[{"months": 12, "product": "car"}]"

I need to know the count of json objects in string and get values based on that

Capuchin
  • 3,207
  • 5
  • 27
  • 39

1 Answers1

1

use json module

json_string = '[{"product": "car", "months": 12}, {"product": "bike", "months": "12"}]'

import json
data = json.loads(json_string)
print data[0], len(data)
Anshul Goyal
  • 67,326
  • 35
  • 140
  • 172