Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse json dump #3284

Closed
qleguennec opened this issue Jul 17, 2014 · 4 comments
Closed

Unable to parse json dump #3284

qleguennec opened this issue Jul 17, 2014 · 4 comments

Comments

@qleguennec
Copy link

@qleguennec qleguennec commented Jul 17, 2014

Hello,

I'm trying to parse a simple JSON dump. No matters what dump i try to parse, the JSON reader gives me an error.

 youtube-dl "ytsearch:dark side of the moon -j >> db"

Parsing it with an online json parser, i got this error:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data

My final purpose is to parse it with a haskell JSON library.

@phihag
Copy link
Contributor

@phihag phihag commented Jul 17, 2014

Your command line will not output JSON since the quotes are wrong. If you want the JSON in a file db, use

youtube-dl "ytsearch:dark side of the moon" -j > db
@phihag phihag closed this Jul 17, 2014
@qleguennec
Copy link
Author

@qleguennec qleguennec commented Jul 17, 2014

Sorry, you're right, i used the command line you mentionned, not the first one, of course.
My json file seems right. Have a look: http://pastebin.archlinux.fr/522174

That's sad. The isssue shouldn't be closed.

@phihag
Copy link
Contributor

@phihag phihag commented Jul 17, 2014

That file contains valid JSON, two concated documents. Have you run the command with >> instead of >, and ran it twice?

Simply replace >> with > to overwrite the file. Note that when youtube-dl retrieves multiple results (say, you're downloading a playlist, or simply passing in multiple URLs), youtube-dl will output multiple lines, each of which consists of an individual valid JSON document.

We implemented this behavior because it means that you can ask for multiple URLs and get JSON documents while youtube-dl is extracting the information, instead of having to wait for youtube-dl to extract everything. Would it be more convenient for your application to get all of the results as a single JSON document? Note that you still have to use > instead of >> then.

@qleguennec
Copy link
Author

@qleguennec qleguennec commented Jul 22, 2014

Thank you for your help, problem solved.
The issue was actually that my library (haskell's Aeson) was parsing only one line of the dump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.