hj is a command line tool to convert HTTP/1-style text into JSON

Overview

hj CI

hj is a command line tool to convert HTTP/1-style text into JSON.

This command is inspired by yusukebe/rj, which is a standalone HTTP client that shows HTTP responses in JSON. On the other hand, this command is not an HTTP client but a simple text filter that translates a result of an external HTTP client such as curl(1).

Synopsis

Simple usage with curl(1):

# -sv is required to output HTTP response headers.
$ curl -sv https://httpbin.org/get 2>&1 | hj | jq .

The output may be:

\n\n\n Example Domain\n\n \n \n \n \n\n\n\n
\n

Example Domain

\n

This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.

\n

More information...

\n
\n\n\n" }">
{
  "protocol": "HTTP/1.1",
  "status_code": 200,
  "headers": {
    "accept-ranges": "bytes",
    "age": "417384",
    "cache-control": "max-age=604800",
    "content-type": "text/html; charset=UTF-8",
    "date": "Tue, 25 Jan 2022 04:28:00 GMT",
    "etag": "\"3147526947\"",
    "expires": "Tue, 01 Feb 2022 04:28:00 GMT",
    "last-modified": "Thu, 17 Oct 2019 07:18:26 GMT",
    "server": "ECS (sab/56BC)",
    "vary": "Accept-Encoding",
    "x-cache": "HIT",
    "content-length": "1256"
  },
  "content": "\n\n\n    Example Domain\n\n    
  \n    
  \n    
  \n        \n\n\n\n
  
\n

Example Domain

\n

This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.

\n

More information...

\n
\n\n\n" }

If the response is JSON (content-type: application/json), its content is automatically parsed as JSON:

curl -sv https://jsonplaceholder.typicode.com/todos/1 2>&1 | hj | jq .

output:

{
  "protocol": "HTTP/1.1",
  "status_code": 200,
  "headers": {
    "date": "Tue, 25 Jan 2022 04:57:52 GMT",
    "content-type": "application/json; charset=utf-8",
    "content-length": "83",
    "connection": "keep-alive",
    "x-powered-by": "Express",
    "x-ratelimit-limit": "1000",
    "x-ratelimit-remaining": "999",
    "x-ratelimit-reset": "1631494143",
    "vary": "Origin, Accept-Encoding",
    "access-control-allow-credentials": "true",
    "cache-control": "max-age=43200",
    "pragma": "no-cache",
    "expires": "-1",
    "x-content-type-options": "nosniff",
    "etag": "W/\"53-hfEnumeNh6YirfjyjaujcOPPT+s\"",
    "via": "1.1 vegur",
    "cf-cache-status": "HIT",
    "age": "13133",
    "accept-ranges": "bytes",
    "expect-ct": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
    "report-to": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=kfDw3zHT7KgD4%2FmRBWFv5gYnwzVVSqFH5N%2F9sTmdI425jb9mZyZggJNoeaYF2%2B%2FdEQ57JdVJggqDJZSRKt5YX%2BStzgoYRGmSwcsQ5M%2Bd1vD9rzT72hrwQfh62ZXPa01QSJxhEpyJUmf7y8BVuagT\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
    "nel": "{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}",
    "server": "cloudflare",
    "cf-ray": "6d2eec5508f10ac0-NRT",
    "alt-svc": "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400"
  },
  "content": {
    "completed": false,
    "userId": 1,
    "title": "delectus aut autem",
    "id": 1
  }
}

Install

cargo(1) and rustc(1) (>= v1.58) are required to install:

cargo install --path .

Supported Commands

License

Copyright 2022 FUJI Goro.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

You might also like...
a command-line tool that transforms a Git repository into a minimal format for ChatGPT queries
a command-line tool that transforms a Git repository into a minimal format for ChatGPT queries

gprepo /dʒiːpiːˈɹi:pi:oʊ/ a command-line tool that transforms a Git repository into a minimal format for ChatGPT queries. Features Excludes LICENSE an

Functional command-line JSON processor
Functional command-line JSON processor

rq rq is a tiny functional language with which you can manipulate JSON. Basically, it is (an insignificant subset of!) jq, written in Rust. NOTE: This

Tool to allow parsing large JSON files without laoding into memory
Tool to allow parsing large JSON files without laoding into memory

Tool to allow parsing large JSON files without laoding into memory. Developed in Rust with adapters in other programming langauges for easy adoption

colorStyle is a library of styles for command-line text write in Rust.
colorStyle is a library of styles for command-line text write in Rust.

Colorstyle colorStyle is a library of styles for command-line text. Inspired by flylog/colorstyle (golang) Example let text = colorstyle::green("gre

A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!
A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!

uwuifyy A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text! Logo Credits: Jade Nelson Tab

A command-line utility which aligns a block of text within the terminal (or a specified number of columns), written in Rust.
A command-line utility which aligns a block of text within the terminal (or a specified number of columns), written in Rust.

align: a command line utility for aligning text. ⭐ Overview Aligns text within the terminal (or a specified number of columns). The text is treated as

Pink is a command-line tool inspired by the Unix man command.

Pink is a command-line tool inspired by the Unix man command. It displays custom-formatted text pages in the terminal using a subset of HTML-like tags.

Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and at compile-time.
Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and at compile-time.

rgb2ansi256 rgb2ansi256 is a small Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and const fn. Th

🏭 Convert Markdown documents into themed HTML pages with support for code syntax highlighting, LaTeX and Mermaid diagrams.
🏭 Convert Markdown documents into themed HTML pages with support for code syntax highlighting, LaTeX and Mermaid diagrams.

Marky Markdown Magician 🧙 Features Hot reload previewing 🔥 Conversion to HTML / PDF 🏭 Themes! ✨ Extensions - Math, diagrams, syntax-highlighting 🧩

Comments
  • Use write_all to avoid partial writes

    Use write_all to avoid partial writes

    Reference

    • https://doc.rust-lang.org/std/io/trait.Write.html#method.write_all
    • https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount

    (Sorry if you have already known cargo clippy) cargo clippy detects such warnings/error as below. I recommend that you use it. You can also run cargo clippy on save on Visual Studio Code with some configurations. (However it makes VScode a bit slow )

    warning: unneeded `return` statement
       --> src/main.rs:295:5
        |
    295 |     return Ok(());
        |     ^^^^^^^^^^^^^^ help: remove `return`: `Ok(())`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
    
    error: written amount is not handled. Use `Write::write_all` instead
       --> src/main.rs:273:5
        |
    273 |     std::io::stdout().write(b"{")?;
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `#[deny(clippy::unused_io_amount)]` on by default
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount
    
    opened by syohex 1
Owner
FUJI Goro
software engineer. I love programming!
FUJI Goro
This is a simple command line application to convert bibtex to json written in Rust and Python

bibtex-to-json This is a simple command line application to convert bibtex to json written in Rust and Python. Why? To enable you to convert very big

null 3 Mar 23, 2022
A simple (but really fast!) CLI tool to convert an epub into a text file.

epub_to_txt A simple (but really fast!) CLI tool written in Rust to convert an epub into a text file (in Markdown format). Usage epub_to_txt filename.

Darren Mothersele 3 Jul 30, 2023
Command-line tool that provides a workflow for extending, editing, diffing, and writing to vim-style grep lines.

Grug Grug is a command-line tool that provides a workflow for expanding, editing, diffing, and writing edits to files using vim-styled grep lines (suc

null 4 Apr 25, 2023
Command line tool to convert env variables beginning with user to a htpasswd file

envhtp This command line tool converts environment variables whose keys start with "user_" into htpasswd compatible username/password pairs. The goal

Florian Neumann 1 Apr 5, 2022
Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

William D. Jones 5 Aug 20, 2022
Command-line HTTP client for sending a POST request to specified URI on each stdin line.

line2httppost Simple tool to read lines from stdin and post each line as separate POST request to a specified URL (TCP connection is reused though). G

Vitaly Shukela 3 Jan 3, 2023
create and test the style and formatting of text in your terminal applications

description: create and test the style and formatting of text in your terminal applications docs: https://docs.rs/termstyle termstyle is a library tha

Rett Berg 18 Jul 3, 2021
Command line linguistic tools: display pronunciation, convert between regional norms of orthography

Command line linguistic tools: display pronunciation, convert between regional norms of orthography; support for multiple modern and ancient languages: English, Latin, Polish, Quechua, Tikuna

Piotr Bajdek 7 Nov 28, 2022
A tool to convert old and outdated "characters" into the superior Rustcii-Encoding.

rustcii A tool to convert old and outdated "characters" into the superior Rustcii-Encoding. Speak your mind. Blazingly ( ?? ) fast ( ?? ). Github | cr

null 8 Nov 16, 2022
ripsecrets is a command-line tool to prevent committing secret keys into your source code.

ripsecrets is a command-line tool to prevent committing secret keys into your source code. ripsecrets has a few features that distinguish it from other secret scanning tools:

Brian Smith 588 Dec 30, 2022