Skip to content

7.76.1 outputs invalid JSON in --write-out %{json} (a few versions back it was still fine) #6905

@michalrus

Description

@michalrus

I did this

$ curl --write-out '%{json}' https://google.com/ --output /dev/null --silent 

{"content_type":"text/html; charset=UTF-8","errormsg":null,"exitcode":0,"filename_effective":"/dev/null","ftp_entry_path":null,"http_code":301,"http_connect":000,"http_version":"2","local_ip":"10.0.2.100","local_port":45384,"method":"GET","num_connects":1,"num_headers":12,"num_redirects":0,"proxy_ssl_verify_result":0,"redirect_url":"https://www.google.com/","referer":null,"remote_ip":"142.250.185.206","remote_port":443,"response_code":301,"scheme":"HTTPS","size_download":220,"size_header":639,"size_request":72,"size_upload":0,"speed_download":1057,"speed_upload":0,"ssl_verify_result":0,"time_appconnect":0.133558,"time_connect":0.046523,"time_namelookup":0.005388,"time_pretransfer":0.133639,"time_redirect":0.000000,"time_starttransfer":0.206770,"time_total":0.208079,"url":"https://google.com/","url_effective":"https://google.com/","urlnum":0,"curl_version":"libcurl/7.76.1 OpenSSL/1.1.1j zlib/1.2.11 brotli/1.0.9 nghttp2/1.42.0"}

Notice this part:

"http_connect":000

This is not valid JSON, and it breaks different parsers:

Error: Parse error on line 8:
...1,	"http_connect": 000,	"http_version"
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

Perhaps you could add a unit test to verify said JSON validity with some external tool?

I expected the following

Valid JSON.

curl/libcurl version

curl 7.76.1 (x86_64-alpine-linux-musl) libcurl/7.76.1 OpenSSL/1.1.1j zlib/1.2.11 brotli/1.0.9 nghttp2/1.42.0
Release-Date: 2021-04-14
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS brotli HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets

operating system

alpine:3.13.2 on:

Linux 1df3df7de41f 5.10.23 #1-NixOS SMP Thu Mar 11 13:17:30 UTC 2021 x86_64 Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions