question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to filter JSON or XML

See original GitHub issue

Sometimes API responses contain a lot of data.

Given an endpoint that returns JSON or XML, it would be cool to be able to do something like

http http://myapi.endpoint/ -q "abc/xyz"

and only get to see the “abc/xyz” sub-tree of the response.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
jakubroztocilcommented, Jan 7, 2015

I’m afraid this is slightly beyond the scope of what httpie should support. jq for JSON is excellent and integrates well with HTTPie via pipes. I’m planing on adding some examples to the docs, but here is a simple one for now:

$ http httpbin.org/get
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 398
Content-Type: application/json
Date: Wed, 07 Jan 2015 19:03:04 GMT
Server: gunicorn/18.0
Via: 1.1 vegur

{
    "args": {},
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Connect-Time": "1",
        "Connection": "close",
        "Host": "httpbin.org",
        "Total-Route-Time": "1",
        "User-Agent": "HTTPie/0.8.0",
        "Via": "1.1 vegur",
        "X-Request-Id": "2b2e03a0-0449-40f1-9027-73bfe9edf31f"
    },
    "url": "http://httpbin.org/get"
}
$ http httpbin.org/get | jq '.headers["User-Agent"]'
"HTTPie/0.8.0"

And other tools exist for querying different formats.

0reactions
msabramocommented, Feb 19, 2017

Here’s another example of using jq; this one happens to also use httpie-unixsocket to communicate with Docker over /var/run/docker.sock:

$ http http+unix://%2Fvar%2Frun%2Fdocker.sock/info | jq .RegistryConfig
{
  "InsecureRegistryCIDRs": [
    "127.0.0.0/8"
  ],
  "IndexConfigs": {
    "docker.io": {
      "Name": "docker.io",
      "Mirrors": null,
      "Secure": true,
      "Official": true
    }
  },
  "Mirrors": null
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ability to filter JSON or XML · Issue #291 · httpie/httpie - GitHub
Given an endpoint that returns JSON or XML, it would be cool to be able to do something like http http://myapi.endpoint/ -q "abc/xyz"...
Read more >
A Deep Look at JSON vs. XML, Part 1: The History of Each
Numerous articles insist that JSON is superior to XML due to its terse semantics and discount XML as an inefficient and confusing standard...
Read more >
QUERYING JSON AND XML - DiVA Portal
querying functions in JSON and XML to filter values from a dataset and then display them through the HTML5 canvas technology.
Read more >
Javascript form filter based on json or XML to make option boxes
I am trying to think up a filter method based on AJAX, XML or Json. I would like to hear from anyone who...
Read more >
Parse text as JSON or XML (Power Query) - Microsoft Support
To help illustrate how to use the Parse command, the following sample data starts with JSON and XML data entered as text fields....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found