1

I have to import content for Json url in other site. (its almost more than 100K content)

here code i use (i am using requset for download josn file, and mongodb for saving data)

request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
var content = JSON.parse(body);
    // ....
    }
})

Everything work well but after 50K content imoprted i got this error

SyntaxError: Unexpected token <
    at Object.parse (native)
    at Request._callback (/home/app/app.js:58:30)
    at Request.self.callback (/home/app/node_modules/request/request.js:360:22)
    at Request.emit (events.js:98:17)
    at Request.<anonymous> (/home/app/node_modules/request/request.js:1202:14)
    at Request.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/home/app/node_modules/request/request.js:1150:12)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickCallback (node.js:448:13)

i will be appreciated if tell where i am wrong.

2
  • 1
    Just a wild guess, but maybe there's an unexpected token ">" in your JSON. Commented May 26, 2015 at 6:23
  • @torazaburo i found cause problem , in my source some page JSON is broken and have this error Malformed JSON , now i just need to know how i can prevent node from exiting my app Commented May 26, 2015 at 17:51

1 Answer 1

1

What is the source of the JSON file? Is it reliable? Review the JSON that is being parsed - "<" is very unusual for JSON, so it's probably not properly escaped.

I would also put a try { } catch(e) { } statement around your JSON.parse(body);

Sign up to request clarification or add additional context in comments.

10 Comments

here is my source wikiseda.com/dapp/… Is it reliable? well its only option i have.
Hmm.. are you sure that's what you are pulling? It was 2.6kb in size and when I ran JSON.parse() in my browser console, it parsed fine. You are saying what you are downloading is 100K. Is that 100Kb? Please clarifyi
i using request for downloading and using JSON.parse() method , i dont think be any different.
i found cause problem , in my source some page JSON is broken and have this error Malformed JSON , now i just need to know how i can prevent node from exiting my app.
Aha - I was right! try catch shouldn't end process btw - did you use it right?
|

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.