curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: -w %{JSON}

From: Daniel Stenberg via curl-users <>
Date: Fri, 22 May 2020 23:09:46 +0200 (CEST)

On Fri, 22 May 2020, Коваленко Анатолий Викторович via curl-users wrote:

>> Sure it is described. They're all "variables" so you'll get them all output.
>> But why would you do that if you want (valid) JSON?
> For another options, reuse behavior is known. But not for full set in
> combination with particular set. It is inconvenient. Sometimes it is need to
> get one value quickly without parsing at the others (for example, for
> debugging and screen output – one line but not dozens). Such a combination
> can simply be wrong. How does the program respond to an input error?

That's easy: if you want one or a few specific variables output, then don't
use %{json}. The json variable will output them *all*. In JSON format.

>> It will be a valid JSON object and there's no guarantee or promise how many
>> lines that is. It isn't something you should depend upon!
> If there are multiple lines, how do I find the last one?

You parse the JSON! The point with the JSON output is that it is a full, JSON
compliant object. It is meant to be parsed by something that understands JSON.
Such a parser should not care if that data is one, three or seven lines as
long as it is valid and correct JSON.

> Where is the beginning and where is the end of the JSON object?

Are you outputting JSON without understanding JSON? That sounds like a bad
idea. Maybe instead opt to output invididual variables?

> What is the «JSON object» in terms of «MS PowerShell»?

I don't understand. How does PowerShell change JSON?

> There is a string and an array of strings. There are no «JSON objects».

A JSON object is text formatted correctly to follow the JSON syntax.

> Test youself the property «.GetType()» of curl output and be sure.

Sorry, I've heard the name PowerShell but I've never used it and I'm not sure
I see the relevance here. The output from curl is not specific to any
particular type or flavor of shell or command prompts. It outputs text. And in
this case, you chose to get that text formatted as a JSON object. If you don't
like JSON, maybe not ask for JSON?

> An what is the «JSON object» in «MS Cmd.exe»?

I don't understand the question!

  / | Commercial curl support up to 24x7 is available!
                   | Private help, bug fixes, support, ports, new features

Received on 2020-05-22