changedetection.io icon indicating copy to clipboard operation
changedetection.io copied to clipboard

[feature] What todo about JSON changes and notifications?

Open dgtlmoon opened this issue 3 years ago • 3 comments
trafficstars

When there's a change detected in JSON, how do we represent that output?

At the moment the text-diff does not care about the JSON structure, and will just send the text diff, breaking the JSON format

For example, you have something like

{ 
"name": "John",
"score": 10 
}

If score changes, {diff} will just tell us that score changed, but the actual JSON output is broken and unusable (it would contain only "score": 11 )

I looked at a few JSON-diff tools but they seem to just format the JSON then return the text diff, but in this case, we want the option (or notification token like {new_json}) to be available, where that token is available if the json:... filter is used

Some ideas

  • Token {json_new} the whole JSON structure that got used in the json:... filter from the NEW change
  • Token {json_previous} the whole JSON structure that got used in the json:... filter from the OLD change
  • Token {json_value} just the JSON value that changed (it would contain {"score": 10 })

So you could for example drive some other service with a notification like

url: https://myservice.com/upsert?id={watch_uuid}
body: {json_new}

dgtlmoon avatar Dec 27 '21 12:12 dgtlmoon

json_new and json_previous seem to make most sense to me. Calculating json_value looks more difficult and I'm not sure if it is that useful. Most services do probably request a complete json structure, don't they?

Unpublished avatar Dec 31 '21 13:12 Unpublished

yeah.. tough one, there doesn't seem to exist a standard "JSON difference" type language schema either

dgtlmoon avatar Dec 31 '21 13:12 dgtlmoon

kinda related, you could make a JSON structure instead of <br/> here if configured in the right mode

XPath https://github.com/dgtlmoon/changedetection.io/blob/07c60a6acc47b03f05cebc329515f207277ea578/changedetectionio/html_tools.py#L29

CSS https://github.com/dgtlmoon/changedetection.io/blob/07c60a6acc47b03f05cebc329515f207277ea578/changedetectionio/html_tools.py#L15

then you could JSON Post an object containing a list of news-headlines for example, instead of having it all in one chunk of text

dgtlmoon avatar Jan 05 '22 18:01 dgtlmoon

https://github.com/kpdecker/jsdiff now supports jsonDiff

dgtlmoon avatar Nov 19 '22 14:11 dgtlmoon