0

I have string objects that I believe are the result of a JSON.stringify() call in javascript. The strings look something like this when printed from my python script:

'{hashtags=[], 
  urls=[{url=https://t.com/H9W2D8GojG, 
         expanded_url=https://twitter.com/i/web/status/1202511173138169856,
         display_url=twitter.com/i/web/status/1…, 
         indices=[117, 140]}
        ]
 }'

I can't just call json.loads() on this string because of the lack of inner quotation marks. Is there any way to turn this into a dictionary without manually parsing it?

9
  • 3
    What you've shown will never be the result of calling JSON.stringify. JSON.stringify might produce this, if the input to it is a string, but it will never produce what's shown in the question. Commented Dec 10, 2019 at 18:34
  • Does this answer your question? How to parse somewhat wrong JSON with Python? Commented Dec 10, 2019 at 18:38
  • @T.J.Crowder: They did say they printed it in Python, which would strip the outer quotation marks. It's likely they JSON.stringify-ied a string of pseudo-JSON. Commented Dec 10, 2019 at 18:42
  • @T.J.Crowder I see. I believe JSON.stringify is being used at some point, the string is also saved to an sql database, which I'm reading from. More might be happening behind the scenes, but what I have access to is the string as I showed it. Commented Dec 10, 2019 at 18:42
  • @luis.parravicini I just tried the answers shown there, but none of them worked. Commented Dec 10, 2019 at 18:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.