cli icon indicating copy to clipboard operation
cli copied to clipboard

Document JSON-escaping in "=" syntax

Open wataash opened this issue 5 years ago β€’ 1 comments

In = syntax,

  • double quotes (")
  • back slashes (\)
  • non-ascii characters

are escaped in json.dumps:

$ http -v httpbin.org/post                                      \
    dquote='\"'                                                 \
    multi-line='line 1\nline 2'                                 \
    non-ascii=あ                                                \
    unicodes='\u3053\u3093\u306b\u3061\u306f\u4e16\u754c'       \
    ;
POST /post HTTP/1.1
...
User-Agent: HTTPie/1.0.3

{
    "dquote": "\\\"",
    "multi-line": "line 1\\nline 2"
    "non-ascii": "あ",
                 ^^^^ actually "\u3042" (not utf-8 representation 0xe38182)
    "unicodes": "\\u3053\\u3093\\u306b\\u3061\\u306f\\u4e16\\u754c",
}

HTTP/1.1 200 OK
...

This behavior should be documented, shouldn't it?

It's also notable that the escaping can be avoided with :=:

$ http -v httpbin.org/post                                   \
    dquote:='"\""'                                           \
    multi-line:='"line 1\nline 2"'                           \
    non-ascii:='"あ"'                                        \
    unicodes:='"\u3053\u3093\u306b\u3061\u306f\u4e16\u754c"' \
    ;
POST /post HTTP/1.1
...
User-Agent: HTTPie/1.0.3

{
    "dquote": "\"",
    "multi-line": "line 1\nline 2",
    "non-ascii": "あ",
                 ^^^^ actually "\u3042" (#814)
    "unicodes": "γ“γ‚“γ«γ‘γ―δΈ–η•Œ"
                ^^^^^^^^^^^^^^^^
                 actually "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c"
}

HTTP/1.1 200 OK
...

(Note that non-ascii characters can't avoid escaping, see #814)

wataash avatar Nov 02 '19 11:11 wataash

What tasks remain in this issue? If the documentation needs to be updated, where does it need to be updated?

t-mangoe avatar Jan 14 '23 01:01 t-mangoe

Hi. I have not seen this issue in 3 years and things seem to have changed. Please wait a moment while I update it.

wataash avatar Jan 21 '23 03:01 wataash

The description was not well written and was difficult to understand, sorry. I've updated it.

And now I have changed my mind, this is an intuitive specification, no document needed. I'm closing this issue, thank you for looking it over!

wataash avatar Jan 21 '23 08:01 wataash