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

Incorrectly parsing JSON #574

Closed
poskadesign opened this issue Apr 13, 2017 · 7 comments
Closed

Incorrectly parsing JSON #574

poskadesign opened this issue Apr 13, 2017 · 7 comments

Comments

@poskadesign
Copy link

Hey,

First of all, httpie is a magnificent piece of software. I can't remember how many colleagues I recommended using it.

There's a problem I've encountered. According to the spec providing JSON params is done via the := operator. But launching httpie 0.9.9 with these params:

http post localhost/example/ param1="a b c" param2=d jparam:='["test string"]'

Results in a message about invalid JSON. But ["test string"] is valid JSON afaik.

http: error: "jparam:='[test string]'": Expecting value: line 1 column 1 (char 0)

Maybe anyone could shed some line on what seems to be wrong?

@Rezaak1024
Copy link

Correct me if I'm wrong, but isn't a JSON object usually in the format {"key":"value"}?

@jkbrzt
Copy link
Member

jkbrzt commented May 14, 2017

@poskadesign the command looks okay and it works for me in Bash. It could be some escaping issue if you use some other shell.

$ http -v httpbin.org/post  param1="a b c" param2=d jparam:='["test string"]'
POST /post HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 61
Content-Type: application/json
Host: httpbin.org
User-Agent: HTTPie/0.9.9

{
    "jparam": [
        "test string"
    ],
    "param1": "a b c",
    "param2": "d"
}
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 568
Content-Type: application/json
Date: Sun, 14 May 2017 10:58:53 GMT
Server: meinheld/0.6.1
Via: 1.1 vegur
X-Powered-By: Flask
X-Processed-Time: 0.000903844833374

{
    "args": {},
    "data": "{\"param1\": \"a b c\", \"param2\": \"d\", \"jparam\": [\"test string\"]}",
    "files": {},
    "form": {},
    "headers": {
        "Accept": "application/json, */*",
        "Accept-Encoding": "gzip, deflate",
        "Connection": "close",
        "Content-Length": "61",
        "Content-Type": "application/json",
        "Host": "httpbin.org",
        "User-Agent": "HTTPie/0.9.9"
    },
    "json": {
        "jparam": [
            "test string"
        ],
        "param1": "a b c",
        "param2": "d"
    },
    "origin": "",
    "url": "http://httpbin.org/post"
}

@rwish
Copy link

rwish commented Jun 27, 2017

Hi, I'm a newbie to open source projects. I would like work on this issue. Could you please provide me with more info?

@agriffis
Copy link

@poskadesign What OS and shell is that? It looks like your shell consumed the double quotes to avoid word-splitting on the space, but then left the single quotes in the argument.

@sriyanfernando
Copy link

It is something like that.. http POST https://httpbin.org/post wicked=witch casts:='["spells", "curses"]' --json

@poskadesign
Copy link
Author

@sriyanfernando still doesn't work (httpie 0.99, Windows 10x64, Python 3.61, standard Windows Command Prompt):

C:\Users\Me>http post localhost:8000/mail/ recipients:='["me@provider.com"]' --json
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
            [--style STYLE] [--print WHAT] [--headers] [--body] [--verbose]
            [--all] [--history-print WHAT] [--stream] [--output FILE]
            [--download] [--continue]
            [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
            [--auth USER[:PASS]] [--auth-type {basic,digest}]
            [--proxy PROTOCOL:PROXY_URL] [--follow]
            [--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
            [--check-status] [--verify VERIFY]
            [--ssl {ssl2.3,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT]
            [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]
            [--traceback] [--default-scheme DEFAULT_SCHEME] [--debug]
            [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
http: error: "recipients:='[me@provider.com]'": Expecting value: line 1 column 1 (char 0)

@agriffis
Copy link

@poskadesign Try this:

http post localhost/example/ param1="a b c" param2=d jparam:="[\"test string\"]"

I'm not very familiar with Windows command line, but found https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line which is similar.

@jkbrzt jkbrzt closed this as completed Sep 5, 2017
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

6 participants