Httpie: Incorrectly parsing JSON

Created on 13 Apr 2017  ·  7Comments  ·  Source: httpie/httpie

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?

Most helpful comment

@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.

All 7 comments

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

@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"
}

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

@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.

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

@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:='["[email protected]"]' --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:='[[email protected]]'": Expecting value: line 1 column 1 (char 0)

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Govinda-Fichtner picture Govinda-Fichtner  ·  6Comments

rshurts picture rshurts  ·  5Comments

Abdallah-Obaid picture Abdallah-Obaid  ·  4Comments

k0pernikus picture k0pernikus  ·  3Comments

filipesperandio picture filipesperandio  ·  3Comments