0

I want to extract specific data from String of list of dictionaries but unable to do

I have performed json.loads operation but still getting error

import json
data =json.loads("[{'id': 35, 'name': 'Comedy'}]")
Traceback (most recent call last)

JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • This is not valid JSON. JSON uses "double quotes" not 'single quotes' – khelwood Jun 11 '19 at 06:49
  • 1
    `json.loads("[{'id': 35, 'name': 'Comedy'}]".replace("'", "\""))` – Olvin Roght Jun 11 '19 at 06:50
  • 1
    Try to google error message first next time before creating new question: https://stackoverflow.com/questions/39491420/python-jsonexpecting-property-name-enclosed-in-double-quotes – dfsq Jun 11 '19 at 06:51
  • I have already seen that question before posting the question. I have tried that method before posting question. That solution was not able to resolve error that's why I have posted this question – Rajat Arora Jun 12 '19 at 12:46

1 Answers1

0

change ' to "

import json
data =json.loads("[{\"id\": 35, \"name\": \"Comedy\"}]")

or

import json
data =json.loads('[{"id": 35, "name": "Comedy"}]')
verejava
  • 7
  • 5