1

I am trying to convert this string into a dictionary using the JSON library.

string = {u'ItemID': u'474178239', u'Status': 1, u'ImageURL': u'https://img.shopstyle-cdn.com/pim/d2/1a/d21a5497da25891c11ce39e54a1171db_best.jpg', u'Last_Modified_Date': {u'$date': u'2017-08-05T05:28:42.773Z'}, u'ClientID': 6, u'Creation_Date': {u'$date': u'2017-08-05T05:28:42.773Z'}, u'ImageName': u'288216716fb441b5f07bc61b7fc827a9.jpg', u'_id': '55315426_03', u'CategoryID': u'18019', u'Metadata': {u'productPageURL': u'https://www.shopstyle.com/p/gianvito-rossi-vamp-100-suede-ankle-boots-black/474178239', u'price': u'895', u'description': u"<![CDATA[\n                        Cap off sophisticated evening looks with Gianvito Rossi's black ankle boots. Crafted in Italy from the finest suede , this almond-toe design has a low-cut, split vamp and extended topline. Wear yours with everything from dresses to tailored pants.\n                        ]]>", u'style': u'boots', u'title': u'Gianvito Rossi - Vamp 100 Suede Ankle Boots - Black'}}

The string is definitely in string format:

type(string)
str

However when I try to convert it into a dictionary using:

dictionary = json.loads(string)

I get:

ValueError: Expecting property name: line 1 column 2 (char 1) 

Is there anyway I can get around this?

2
  • 2
    The code you provided for variable string is not string it is dict. Commented Oct 12, 2017 at 13:44
  • So, is your value "string = {u'..." (a snippet of Python code as string), or "{u'..." (a Python dictionary literal as string), or {u'... (a dictionary)? That's rather nebulous. Commented Oct 12, 2017 at 13:49

1 Answer 1

3

The provided object is a dictionary. However, try using the ast library :

import ast
ast.literal_eval(string)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.