Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

add (with recursive: true) returns improperly-formatted JSON #82

Closed
tinybike opened this issue Oct 22, 2015 · 6 comments
Closed

add (with recursive: true) returns improperly-formatted JSON #82

tinybike opened this issue Oct 22, 2015 · 6 comments
Labels

Comments

@tinybike
Copy link

The add method (with recursive: true) isn't returning properly-formatted JSON for me. Instead I get a string that almost looks like JSON, but isn't actually, so to parse it I have to do some string mangling. Example:

var ipfs = require("ipfs-api")("localhost", "5001");
ipfs.add("./ipfs", {recursive: true}, function (err, res) {
            if (err || !res) return console.error(err);
            console.log(res);
});

This prints out:

{
  "Name": "funcrusher.json",
  "Hash": "QmUSpeNRKrYHRG55WvYTi5u3VVHaP3uHtH1mDKCB9Qa9AJ"
}{
  "Name": "ipfs",
  "Hash": "QmYuDw2SxfWkFasmmenzsdKSV7QVHAEuevAuCjcDh8kEYt"
}{
  "Name": "",
  "Hash": "QmWike1KhJRzY4EMtreidZDgq1EhYpLY444pfVJxxD3wSp"
}

(Note the lack of commas between the objects, and lack of enclosing array brackets.)

@travisperson
Copy link
Contributor

This might be an issue with the daemon. It would appear that it may not be properly chunking the response coming back. If I had to guess the x-chunked-output header is missing.

@whyrusleeping
Copy link
Contributor

many of our commands return a stream of json objects, not a json array. This is so that consumers of the api can act on the output before receiving the entirety of the output. Most json decoders (all of them that i've used) are able to handle this pretty well.

The one issue that we have though, is that we should be putting newlines between the objects to be true 'ndjson'.

@whyrusleeping
Copy link
Contributor

the newline part should be fixed here: ipfs/kubo#1885

@travisperson
Copy link
Contributor

This also may be causing issues: ipfs/kubo#1882

@daviddias
Copy link
Contributor

@tinybike IPFS HTTP API started returning ndjson on 0.3.8, while in 0.3.7 returned a JSON array. This module is expecting a JSON array and trying to perform a parse on it, but since it is not valid JSON, it returns it as a string. We are working to upgrade it, but prioritised tests first #81, once tests are ready (tested against 0.3.7) we will add a proper ndjson parser. The focus on tests first is exactly to avoid this kind of bugs with API changes in the future. Sorry for the trouble, confusion.

@daviddias
Copy link
Contributor

solved with latest release and IPFS 0.3.9 :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants