-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,465
  • 6
  • 28
  • 40

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
  • 73,278
  • 37
  • 149
  • 186