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

Already on GitHub? Sign in to your account

How come response "automatically" determines whether it's a string or JSON? #113

felixchan opened this Issue Nov 24, 2011 · 7 comments


None yet
3 participants

If I run this...depending on "body", this library automatically determines whether it's json or string type.

Is this normal?

},function(err, response, body){
    console.log(typeof body);  //sometimes prints string, sometimes prints json

Even though my response headers are always:

'content-type': 'text/html; charset=utf-8',


mikeal commented Nov 24, 2011

because you turned on json handling, that's what json:[truthy value] does.

it shouldn't give you a json object if it's html though because it should fail to parse and fall back to a string.

Thanks mikeal.

How do I turn OFF JSON handling?

I want it to always be "string". because sometimes it'll be HTML, sometimes it'll be JSON. But I want to treat it myself



mikeal commented Nov 24, 2011

  { uri: uri
  , body: JSON.stringify(data)
  , headers:{'content-type':'application/json'}

kilianc commented Nov 24, 2011

i don't think that the typeof operator can return json as value.
Two possible values could be object or string

@killianc your'e right :) it returns object or string haha

Thanks mikeal

@felixchan felixchan closed this Nov 24, 2011


mikeal commented Nov 24, 2011

no problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment