httpie / cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
https://httpie.io
BSD 3-Clause "New" or "Revised" License
33.56k stars 3.67k forks source link

can httpie support JSON5 (JSON for Humans) input? #1402

Open tx0c opened 2 years ago

tx0c commented 2 years ago

Checklist


Enhancement request

trying to call httpie with post body including raw valid js objects,

http <url> metrics:='[{name: "activeUsers"}]'

got error:

'metrics:=[{name: "activeUsers"}]': Expecting property name enclosed in double quotes: line 1 column 3 (char 2)

as expected;

but always expected tools like httpie could/should accept more format for flexibility,

and there is a project for that, called JSON5 (https://json5.org/) JSON for Humans, it allows many features, and some would be most useful for httpie:

  1. Object keys may be an ECMAScript 5.1 IdentifierName, with single quote, or without quote, if unambiguous, like my example: metrics:='[{name: "activeUsers"}]' hope httpie can recognize it and auto-translate to valid json,
  2. Strings may be single quoted,
  3. Numbers may be hexadecimal, or scientific format, like 1e3 28e6 ?

Additional information, screenshots, or code examples

JSON5 Python libraries:

  1. https://pypi.org/project/json5/
  2. https://pyjson5.readthedocs.io/
isidentical commented 2 years ago

Hey @tx0c, thanks for the suggestion! This needs a bit more work than just adding another check, since we want to be backwards compatible and warn our users in case of they are sending wrong JSON objects (even though those might be valid in JSON5). We need some product design first, in order to asses how we want to proceed (e.g a new --json5 flag, accompaniying the existing --json).