curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: json awareness ?

From: Tony Aiuto via curl-users <curl-users_at_cool.haxx.se>
Date: Wed, 27 Sep 2017 21:48:56 -0400

On Sun, Sep 24, 2017 at 7:58 AM, <lars_at_bombocla.at> wrote:

> I'm not really much of a heavy json user myself, but I created a wiki page
>> for
>> collecting ideas and allow brainstorming arund what improve json support
>> in
>> curl *might* be!
>>
>
> Hey,
>
> I don't know if this is the proper way to respond,
> first time using a mailing list :D
>
> My current use of curl is to get json data from a hit rate limited API.
> I can limit the bandwidth usage but not how many requests per x time from
> a list of urls.
> So for now I have to use libcurl to do this type of rate limiting outside
> of curl.
>
> Another way of JSON awareness could be providing the headers in JSON
> format.
> For example the combined output of headers and body would look something
> like this:
>
> {
> "headers": [
> {
> "Content-Type": "application/json"
> },
> {
> "etc": "etc"
> }
> ]
> }
> {"example": "json_answer"}
>
> This can be read by jq directly and then used to process the data
> differently.
>
> lars

I think it is more useful if headers are a single dictionary, rather than a
list of single item dictionaries.

{
  "http_code": 200,
  "headers": {
    "Content-Type": "application/json".
    "Last-Modified": "....",
    "ETag": "\"134a-6d5-530904afbe7c0|"",
     ...
 }
}

They must be a separate output stream from the body. Something like:

   curl --dump-header header.json --header-format=json http://foo.com/baz
>body.json

Now the script calling this can examine the headers and decide what to do
about the body. You can't rely on servers returning valid JSON in the body
for non 200 responses, so if they were in one stream, you might never be
able to parse the header section with most JSON tools.

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-09-28