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

remove need for quotes to be escaped for raw json input #77

Closed
avisser opened this issue Jul 25, 2012 · 9 comments
Closed

remove need for quotes to be escaped for raw json input #77

avisser opened this issue Jul 25, 2012 · 9 comments

Comments

@avisser
Copy link

avisser commented Jul 25, 2012

While it may be intentional, it is quite unintuitive that you need to escape your quotes for raw json input

$> http POST localhost:8888/api/learn/license_check purchased_licenses:=["android.test.purchased"]
http: error: purchased_licenses:=[android.test.purchased] is not valid JSON

but

$> http POST localhost:8888/api/learn/license_check purchased_licenses:=[\"android.test.purchased\"]
HTTP/1.1 200 OK
...

This is in OSX terminal - 10.7.4.

@jkbrzt
Copy link
Member

jkbrzt commented Jul 25, 2012

@avisser It would be nice not having to escape it but the JSON simply needs to be valid after the arguments have been processed by the shell, so it's unfortunately necessary. Otherwise it would require an error-correcting JSON parser to allow unquoted strings.

You can also wrap the whole argument with single quotes ('purchased_licenses:=["android.test.purchased"]'), or It might be easier to pass the JSON in via stdin, such as:

echo '{"purchased_licenses": ["android.test.purchased"]}' | http localhost:8888/api/learn/license_check

# or from a file

http localhost:8888/api/learn/license_check @payload.json

(Tip: POST is default here because you are sending data with your request so you can omit it.)

@avisser
Copy link
Author

avisser commented Jul 26, 2012

I was worried that might be the case. Thanks for the alternatives.

Might I suggest using one of your examples in the readme.rst?

The fact that

blah:=[1,2,3]

and

blah:=["1","2","3"]  #the quotes get stripped, but bare numerals are fine

both work drove me crazy for a few minutes.

Great utility. Keep up the good work.

@avisser avisser closed this as completed Jul 26, 2012
@jkbrzt
Copy link
Member

jkbrzt commented Jul 26, 2012

Good idead, I'll update the README. Cheers

jkbrzt added a commit that referenced this issue Jul 26, 2012
@asemx
Copy link

asemx commented Mar 16, 2013

Still getting below error when i pass with quotes from cmd line 'meals:=["ham", "spam"]' (i notice in the documentation you use = and not := though I tried both)

http-script.py: error: argument REQUEST ITEM: "spam]'" is not a valid value

@asemx
Copy link

asemx commented Mar 16, 2013

to pass string arrays in json from cmd line, i found the below option working:

meals:=["ham","spam"]

thanks btw for this great project.

@jkbrzt
Copy link
Member

jkbrzt commented Mar 16, 2013

It looks like your shell is eating the quotes for some reason. The first form works fine in bash:

Screen Shot 2013-03-16 at 16 48 04

@asemx
Copy link

asemx commented Mar 16, 2013

meals:='["ham","spam"]' with (or without) quotes doesn't work on windows cmd. I have to use '' escapes.

@jkbrzt
Copy link
Member

jkbrzt commented Mar 16, 2013

I misread you comments, but have corrected my answer in the meantime. Sorry for the confusion.

Okay, I understand, there is this nested quoting incompatibility between bash and cmd.exe. I will update the docs accordingly. Thanks.

@afolaran
Copy link

afolaran commented Feb 4, 2016

Hello.

I have just installed httpie and I am trying to perform some aggregate queries on a data base on my local machine. I got the error message;

http-script.py: error: argument REQUEST_ITEM: "[" is not a valid value

What can I do to resolve this? I have tried several options but no success. Below I attach a screenshot of my console

error page

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

No branches or pull requests

4 participants