feat: allow parsing stringified json fields#342
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #342 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 1449 1491 +42
Branches 263 276 +13
=========================================
+ Hits 1449 1491 +42 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I get the idea, but can you give me a use-case or systme that does this? I'm trying to wrap my head around a system that is sending webhooks using stringified json inside of a json response block. It doesn't seem like optimal/ideal coding practices. I feel this PR would just add overhead at the cost of very extreme edge cases. Can you share with me the system that is doing this? It may be worth investing in putting a PR or filing an issue against it? I'm not against this approach; i just need further reason/justificaiton as I don't agree with it right now. Things i spot off hand (besides he overhead of now treating even a simple field mapper (what 99.9999% of people we use it for) into a transformation language (parsed). but not just that, it introduces syntax that can collide with actual field names. I think we need to look for specifically ::json and not catch on ::json-like (basically it catches/matches strings it shouldn't). Mapping in Apprise starts off with Thoughts? |
|
My primary use case for the feature today is for Ofelia, currently they post a stringified JSON under one of the fields in their webhook for a slack integration. Agree this could be something that gets addressed directly in that project itself but figured JSON parsing could be a useful feature that adds more flexibility to apprise to work with all kinds of upstream services regardless of their webhook formatting choices Regarding the edge cases, I have added some tests for ones I could think of, primarily like you mentioned for any field that ends with "::json" already, we prefer to match exact field names before applying any transformations. There is some tests covering this behavior Having multiple fields should not conflict either since the double colon syntax since it doesn't change the query string parsing at all, but I can also add some additional tests to be sure mixing JSON and non JSON field mapping works as expected |
Description
Related issue (if applicable): #
This PR adds support for an explicit double-colon
::jsonmodifier inside third-party webhook payload mapping rules.If a third-party webhook sends a payload containing stringified JSON, you can add
::jsonto that segment name in your mapping rules to instruct the engine to parse the string in-place. This allows you to traverse into the parsed JSON structure using standard dot-notation and bracket-notation, or map the parsed object directly.Features
event::json.info::json.title).items::json[0].valueoritems[0]::json.value).?:event::json=body).::jsonstring, it is matched directly without traversal/parsing, ensuring 100% backward compatibility.format,type,title, andbody) cannot be assigned adictorlistobject. If a type mismatch occurs, it fails validation gracefully (logs a warning and returns HTTP 400) to prevent runtime crashes in downstream notification plugins.Checklist
tox -e lintand optionallytox -e format). (some preexisting html lints exist unrelated to these changes)tox -e test).Testing
Anyone can help test as follows:
Successful Parsing & Mapping: Send a POST request with a nested stringified JSON payload using the ::json modifier in mapping rules:
Verification error case trying to map json to apprise fields