Python not reading valid JSONCalling an external command in PythonWhat are metaclasses in Python?Can comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?Does Python have a ternary conditional operator?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?How to read a file line-by-line into a list?Does Python have a string 'contains' substring method?
Fencing style for blades that can attack from a distance
How to format long polynomial?
In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
How is it possible to have an ability score that is less than 3?
Windows 98 hangs after entering password on fresh install
What is the word for reserving something for yourself before others do?
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
Why dont electromagnetic waves interact with each other?
Why do falling prices hurt debtors?
What are these boxed doors outside store fronts in New York?
Why are 150k or 200k jobs considered good when there are 300k+ births a month?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Which models of the Boeing 737 are still in production?
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
How to find program name(s) of an installed package?
Expeditious Retreat
How old can references or sources in a thesis be?
What do you call a Matrix-like slowdown and camera movement effect?
How does one intimidate enemies without having the capacity for violence?
What does it mean to describe someone as a butt steak?
Can I make popcorn with any corn?
Do I have a twin with permutated remainders?
Python not reading valid JSON
Calling an external command in PythonWhat are metaclasses in Python?Can comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?Does Python have a ternary conditional operator?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?How to read a file line-by-line into a list?Does Python have a string 'contains' substring method?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am scraping some HTML source from a web page to extract data stored in a json format
This is the Code:
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
s = str(s)
s = s[119:-16]
json_data = json.loads(s)
Running the above throws this error:
json.decoder.JSONDecodError: Expecting ',' delimiter: line 1 column 7506 (char7505)
When I take the content of variable s and pass it to a json formatter it's recognized as proper json.
I used the following web site to check the json:
http://jsonprettyprint.com/json-pretty-printer.php
Why is this error coming up when using json.loads() in Python? I am assuming it has something to do with the string not being encoded properly or the presence of escape characters?
How do I solve this?
python html json string encoding
add a comment |
I am scraping some HTML source from a web page to extract data stored in a json format
This is the Code:
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
s = str(s)
s = s[119:-16]
json_data = json.loads(s)
Running the above throws this error:
json.decoder.JSONDecodError: Expecting ',' delimiter: line 1 column 7506 (char7505)
When I take the content of variable s and pass it to a json formatter it's recognized as proper json.
I used the following web site to check the json:
http://jsonprettyprint.com/json-pretty-printer.php
Why is this error coming up when using json.loads() in Python? I am assuming it has something to do with the string not being encoded properly or the presence of escape characters?
How do I solve this?
python html json string encoding
could u print your JSON before json.loads. You must be missing some kind of delimiter in there
– skaul05
Mar 8 at 3:17
The json object is too big for me to post here as text
– Mustard Tiger
Mar 8 at 3:28
add a comment |
I am scraping some HTML source from a web page to extract data stored in a json format
This is the Code:
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
s = str(s)
s = s[119:-16]
json_data = json.loads(s)
Running the above throws this error:
json.decoder.JSONDecodError: Expecting ',' delimiter: line 1 column 7506 (char7505)
When I take the content of variable s and pass it to a json formatter it's recognized as proper json.
I used the following web site to check the json:
http://jsonprettyprint.com/json-pretty-printer.php
Why is this error coming up when using json.loads() in Python? I am assuming it has something to do with the string not being encoded properly or the presence of escape characters?
How do I solve this?
python html json string encoding
I am scraping some HTML source from a web page to extract data stored in a json format
This is the Code:
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
s = str(s)
s = s[119:-16]
json_data = json.loads(s)
Running the above throws this error:
json.decoder.JSONDecodError: Expecting ',' delimiter: line 1 column 7506 (char7505)
When I take the content of variable s and pass it to a json formatter it's recognized as proper json.
I used the following web site to check the json:
http://jsonprettyprint.com/json-pretty-printer.php
Why is this error coming up when using json.loads() in Python? I am assuming it has something to do with the string not being encoded properly or the presence of escape characters?
How do I solve this?
python html json string encoding
python html json string encoding
asked Mar 8 at 3:12
Mustard TigerMustard Tiger
78321333
78321333
could u print your JSON before json.loads. You must be missing some kind of delimiter in there
– skaul05
Mar 8 at 3:17
The json object is too big for me to post here as text
– Mustard Tiger
Mar 8 at 3:28
add a comment |
could u print your JSON before json.loads. You must be missing some kind of delimiter in there
– skaul05
Mar 8 at 3:17
The json object is too big for me to post here as text
– Mustard Tiger
Mar 8 at 3:28
could u print your JSON before json.loads. You must be missing some kind of delimiter in there
– skaul05
Mar 8 at 3:17
could u print your JSON before json.loads. You must be missing some kind of delimiter in there
– skaul05
Mar 8 at 3:17
The json object is too big for me to post here as text
– Mustard Tiger
Mar 8 at 3:28
The json object is too big for me to post here as text
– Mustard Tiger
Mar 8 at 3:28
add a comment |
4 Answers
4
active
oldest
votes
Your JSON contains certain unexpected tokens like true
. Use json.dumps
first to resolve it.
print (json.dumps(s,indent =2))
s = json.dumps(s)
json_data = json.loads(s)
add a comment |
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 7484 (char 7483)
Using the failure message, you can print a slice of the string to see where it is failing.
print(s[7400:7500])
mailboxes.isPrimary=\"true\" AND ymreq
As skaul05 stated, it is failing because of the true
token in the string.
add a comment |
import requests
from bs4 import BeautifulSoup
import json
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
a = s[0][111:-12]
jjjj = json.loads(a)
there's somethingrong when you deal with the list,you just use str()
why? it's just where you wrong? why give me such an evaluation?
– Tom.chen.kang
Mar 8 at 3:55
can you solve this problem by the method the second one provide? hehe
– Tom.chen.kang
Mar 8 at 3:57
add a comment |
If it was a valid JSON formatted text then the parser wouldn't complain. This is how I tested it
//first I scraped that page
curl https://finance.yahoo.com/quote/SPY > SPY.json
//then tried to parse it using json
a = open("SPY.json")
b = json.load(a)
ValueError: No JSON object could be decoded
You probably need to first parse it in to valid xml first.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056192%2fpython-not-reading-valid-json%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your JSON contains certain unexpected tokens like true
. Use json.dumps
first to resolve it.
print (json.dumps(s,indent =2))
s = json.dumps(s)
json_data = json.loads(s)
add a comment |
Your JSON contains certain unexpected tokens like true
. Use json.dumps
first to resolve it.
print (json.dumps(s,indent =2))
s = json.dumps(s)
json_data = json.loads(s)
add a comment |
Your JSON contains certain unexpected tokens like true
. Use json.dumps
first to resolve it.
print (json.dumps(s,indent =2))
s = json.dumps(s)
json_data = json.loads(s)
Your JSON contains certain unexpected tokens like true
. Use json.dumps
first to resolve it.
print (json.dumps(s,indent =2))
s = json.dumps(s)
json_data = json.loads(s)
answered Mar 8 at 3:37
skaul05skaul05
1,0831616
1,0831616
add a comment |
add a comment |
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 7484 (char 7483)
Using the failure message, you can print a slice of the string to see where it is failing.
print(s[7400:7500])
mailboxes.isPrimary=\"true\" AND ymreq
As skaul05 stated, it is failing because of the true
token in the string.
add a comment |
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 7484 (char 7483)
Using the failure message, you can print a slice of the string to see where it is failing.
print(s[7400:7500])
mailboxes.isPrimary=\"true\" AND ymreq
As skaul05 stated, it is failing because of the true
token in the string.
add a comment |
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 7484 (char 7483)
Using the failure message, you can print a slice of the string to see where it is failing.
print(s[7400:7500])
mailboxes.isPrimary=\"true\" AND ymreq
As skaul05 stated, it is failing because of the true
token in the string.
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 7484 (char 7483)
Using the failure message, you can print a slice of the string to see where it is failing.
print(s[7400:7500])
mailboxes.isPrimary=\"true\" AND ymreq
As skaul05 stated, it is failing because of the true
token in the string.
answered Mar 8 at 3:53
ap288ap288
365
365
add a comment |
add a comment |
import requests
from bs4 import BeautifulSoup
import json
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
a = s[0][111:-12]
jjjj = json.loads(a)
there's somethingrong when you deal with the list,you just use str()
why? it's just where you wrong? why give me such an evaluation?
– Tom.chen.kang
Mar 8 at 3:55
can you solve this problem by the method the second one provide? hehe
– Tom.chen.kang
Mar 8 at 3:57
add a comment |
import requests
from bs4 import BeautifulSoup
import json
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
a = s[0][111:-12]
jjjj = json.loads(a)
there's somethingrong when you deal with the list,you just use str()
why? it's just where you wrong? why give me such an evaluation?
– Tom.chen.kang
Mar 8 at 3:55
can you solve this problem by the method the second one provide? hehe
– Tom.chen.kang
Mar 8 at 3:57
add a comment |
import requests
from bs4 import BeautifulSoup
import json
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
a = s[0][111:-12]
jjjj = json.loads(a)
there's somethingrong when you deal with the list,you just use str()
import requests
from bs4 import BeautifulSoup
import json
url = 'https://finance.yahoo.com/quote/SPY'
result = requests.get(url)
c = result.content
html = BeautifulSoup(c, 'html.parser')
scripts = html.find_all('script')
sl =[]
for s in scripts:
sl.append(s)
s = (sl[-3])
s = s.contents
a = s[0][111:-12]
jjjj = json.loads(a)
there's somethingrong when you deal with the list,you just use str()
answered Mar 8 at 3:41
Tom.chen.kangTom.chen.kang
265
265
why? it's just where you wrong? why give me such an evaluation?
– Tom.chen.kang
Mar 8 at 3:55
can you solve this problem by the method the second one provide? hehe
– Tom.chen.kang
Mar 8 at 3:57
add a comment |
why? it's just where you wrong? why give me such an evaluation?
– Tom.chen.kang
Mar 8 at 3:55
can you solve this problem by the method the second one provide? hehe
– Tom.chen.kang
Mar 8 at 3:57
why? it's just where you wrong? why give me such an evaluation?
– Tom.chen.kang
Mar 8 at 3:55
why? it's just where you wrong? why give me such an evaluation?
– Tom.chen.kang
Mar 8 at 3:55
can you solve this problem by the method the second one provide? hehe
– Tom.chen.kang
Mar 8 at 3:57
can you solve this problem by the method the second one provide? hehe
– Tom.chen.kang
Mar 8 at 3:57
add a comment |
If it was a valid JSON formatted text then the parser wouldn't complain. This is how I tested it
//first I scraped that page
curl https://finance.yahoo.com/quote/SPY > SPY.json
//then tried to parse it using json
a = open("SPY.json")
b = json.load(a)
ValueError: No JSON object could be decoded
You probably need to first parse it in to valid xml first.
add a comment |
If it was a valid JSON formatted text then the parser wouldn't complain. This is how I tested it
//first I scraped that page
curl https://finance.yahoo.com/quote/SPY > SPY.json
//then tried to parse it using json
a = open("SPY.json")
b = json.load(a)
ValueError: No JSON object could be decoded
You probably need to first parse it in to valid xml first.
add a comment |
If it was a valid JSON formatted text then the parser wouldn't complain. This is how I tested it
//first I scraped that page
curl https://finance.yahoo.com/quote/SPY > SPY.json
//then tried to parse it using json
a = open("SPY.json")
b = json.load(a)
ValueError: No JSON object could be decoded
You probably need to first parse it in to valid xml first.
If it was a valid JSON formatted text then the parser wouldn't complain. This is how I tested it
//first I scraped that page
curl https://finance.yahoo.com/quote/SPY > SPY.json
//then tried to parse it using json
a = open("SPY.json")
b = json.load(a)
ValueError: No JSON object could be decoded
You probably need to first parse it in to valid xml first.
answered Mar 8 at 3:49
Lawrence KhanLawrence Khan
216
216
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056192%2fpython-not-reading-valid-json%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
could u print your JSON before json.loads. You must be missing some kind of delimiter in there
– skaul05
Mar 8 at 3:17
The json object is too big for me to post here as text
– Mustard Tiger
Mar 8 at 3:28