1

I have a JSON string as a result of a query operation . I assign the result to a string literal and then try to read the string. I get the below error.

SyntaxError: EOL while scanning string literal

I get the result in the below format from a query operation with \n

str = {"start": 0,
  "time": "2015-Mar-15 17:04:33.197042 ::setup Initializing",
  "type": "solar",}

import json
json.loads(str)

Should I convert it into a docstring? I'm using python 3.4

1
  • 2
    Hint: str should be a string. What is type(str)? Also, don't name things after built-in types or functions. Commented Feb 12, 2016 at 20:03

2 Answers 2

7

In your example "str" is already an object, so you dont have to parse it. It has already been parsed.

try this:

str =
{
    "start": 0,
    "time": "2015-Mar-15 17:04:33.197042 ::setup Initializing",
    "type": "solar",
}
print str["start"]

If you had something like this:

str = """
{
    "start": 0,
    "time": "2015-Mar-15 17:04:33.197042 ::setup Initializing",
    "type": "solar",
 }"""

you could do:

import json

json.loads(str)
Sign up to request clarification or add additional context in comments.

Comments

1

In your code str is an object, not a string. To make it a JSON formatted string use:

json.dumps(str)

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.