dgtlmoon / changedetection.io

The best and simplest free open source web page change detection, website watcher, restock monitor and notification service. Restock Monitor, change detection. Designed for simplicity - Simply monitor which websites had a text change for free. Free Open source web page change detection, Website defacement monitoring, Price change notification
https://changedetection.io
Apache License 2.0
16.91k stars 944 forks source link

Indent JSON response #371

Closed jtagcat closed 2 years ago

jtagcat commented 2 years ago

Is your feature request related to a problem? Please describe. GitHub GraphQL API, like many others, responds with no indentation. This makes diffs visually hard to look at.

Describe the solution you'd like Prettify / Indent JSON responses before diffing / saving.

Describe the use-case and give concrete real-world examples Current diff:

-{"data":{"organization":{"repositories":{"edges":[{"node":{"name":"winipcfg-go"}},{"node":{"name":"wintun"}},{"node":{"name":"hujson"}},{"node":{"name":"tailscale"}},{"node":{"name":"wireguard-go"}}]}}}}
+{"data":{"organization":{"repositories":{"edges":[{"node":{"name":"newrepoexample"}},{"node":{"name":"winipcfg-go"}},{"node":{"name":"wintun"}},{"node":{"name":"hujson"}},{"node":{"name":"tailscale"}}]}}}}

Desired:

{
  "data": {
    "organization": {
      "repositories": {
        "edges": [
          {
            "node": {
-              "name": "winipcfg-go"
+              "name": "newrepoexample"
            }
          },
          {
            "node": {
-              "name": "wintun"
+              "name": "winipcfg-go"
            }
          },
          {
            "node": {
-              "name": "hujson"
+              "name": "wintun"
            }
          },
          {
            "node": {
-              "name": "tailscale"
+              "name": "hujson"
            }
          },
          {
            "node": {
-              "name": "wireguard-go"
+              "name": "tailscale"
            }
          }
        ]
      }
    }
  }
}

Showing 'one node object was added, and last was removed' would be nicer, but that's likely too much to ask.

dgtlmoon commented 2 years ago

If you use a filter of json:$* it should select all and re-format, does it work?

dgtlmoon commented 2 years ago

also, shoot me a example URL so i can check the content-type headers etc

jtagcat commented 2 years ago

json:$*

Good idea.

Previous version showed. A system-error occurred when validating your JSONPath expression. There was no meaningful entry in docker logs. When updating to today's version, it almost worked.

As defined in the docs, $* gives all values in a tree (excluding keys). Using json:$ works.

Although, I'd expect indented to be the default, auto-detected. As it looks like too much work, a small 'if you want indented, use this' in the docs sounds better.

I'm not sure if adding it under https://github.com/dgtlmoon/changedetection.io/wiki/JSON-Selector-Filter-help would be best, as the title says filtering-filtering, but people searching will might be turned away by it. Never minding that, as a starting point, I've added it there.
More likely is that it isn't in a visible place, and people will not have the idea to search for it, just having poorer diffs.

Reopen if you have any ideas, or want to keep the issue tracked.

dgtlmoon commented 2 years ago

@jtagcat

also, shoot me a example URL so i can check the content-type headers etc

this would help a lot

jtagcat commented 2 years ago

Ahh, forgot, pardon. I used https://api.github.com/graphql
Headers: Authorization: bearer <gh token>
Body:

{
  "query": "query { organization(login:\"tailscale\") { repositories(first:5, orderBy:{field:CREATED_AT, direction:ASC}) { edges { node { name }}}}}"
}

(this is also possible:)

- first:5,
+ first:5, isFork:false,

https://api.github.com/repos/dgtlmoon/changedetection.io should work as an easier example.