Skip to content

feat: Add json_mode to JS transformation - #444

Merged
Mikhail (oo-sleeper) merged 2 commits into
developfrom
feat-add-json-mode-to-transformations
Aug 14, 2025
Merged

feat: Add json_mode to JS transformation#444
Mikhail (oo-sleeper) merged 2 commits into
developfrom
feat-add-json-mode-to-transformations

Conversation

@oo-sleeper

@oo-sleeper Mikhail (oo-sleeper) commented Aug 5, 2025

Copy link
Copy Markdown
Contributor

ref PDP-1983

json_mode is a new setting for JS transformation, which should make it more transparent into what data is expected as an input to the transformations

If the data is in JSON format, then it would be converted into an object to use in JS script
If the data is not in JSON format, transformation would fail

@oo-sleeper
Mikhail (oo-sleeper) changed the base branch from master to develop August 6, 2025 10:18
@oo-sleeper Mikhail (oo-sleeper) changed the title feat: Add json_mode to transformations feat: Add snowplow_mode_v2 to JS transformation Aug 6, 2025
@oo-sleeper
Mikhail (oo-sleeper) marked this pull request as draft August 6, 2025 10:22
@oo-sleeper
Mikhail (oo-sleeper) marked this pull request as ready for review August 6, 2025 16:16
@phil-snowplow

Copy link
Copy Markdown

One minor quip about naming: if this supports any JSON input and snowplow TSV, then snowplow_mode doesn't really describe it accurately: it's actually snowplow_tsv_and_any_json mode. Seems confusing from a user perspective.

Also, I see we try to parse as tsv and if that fails, parse as json. Is that going to add any unnecessary overhead in cases where we know the input is always going to be json? Or are we not concerned about that?

@colmsnowplow

Copy link
Copy Markdown
Collaborator

It's a bit rock and hard place Phil Catterall (@phil-snowplow) - I'm happy to hear suggestions for a better name!

If this supports any JSON input and snowplow TSV, then snowplow_mode doesn't really describe it accurately: it's actually snowplow_tsv_and_any_json mode. Seems confusing from a user perspective

My take is this:

  • We have an existing snowplow_mode which only works with snowplow data
  • We're extending it to work with another form of Snowplow data
  • By happenstance it'll also work with json data

Nothing actually changes for someone whose data was another JSON - except that there's now a workaround. I'd rather not have that be advertised support for any JSON, simply because I don't think there's any real ask from users to do so. So I'm ok with it being named this even though it happens to also do something else.

I guess the goal isn't to describe the precise functionality as accurately as possible, but to describe the use case we're supporting with it.

Which leads to the answer to:

Is that going to add any unnecessary overhead in cases where we know the input is always going to be json? Or are we not concerned about that?

Yeah it does, if we were doing generic JSON support I'd have a concern and design it differently, but because we're supporting a specific internal use case here, I don't.

The order of operations should be TSV first because that's the prod scenario where latency matters. The other use case is in a testing flow so it's fine to have the extra bit of work.

Next breaking release I think we should clean this up. Then, we can do it as follows:

  • Assume the data is JSON and try to provide it as such
  • Have this feature for TSV/JSON
  • We can also configure it to provide the data as a string instead, no matter what the data is

@oo-sleeper

Copy link
Copy Markdown
Contributor Author

Next breaking release I think we should clean this up. Then, we can do it as follows:

  • Assume the data is JSON and try to provide it as such
  • Have this feature for TSV/JSON
  • We can also configure it to provide the data as a string instead, no matter what the data is

on this one I'd probably suggest something a bit more breaking, but making more sense long-term

at the source level, explicitly specify what the data format is (start with JSON/TSV)
and thus reduce any need to hassle with translations/figuring out what's going on in transformations

from there on, we would be able to add support for anything else (be it CSV or just plain strings) with clearer logic how it gets transformed

@phil-snowplow

Copy link
Copy Markdown

Yeah it does, if we were doing generic JSON support I'd have a concern and design it differently, but because we're supporting a specific internal use case here, I don't.

colmsnowplow that's a fair point – if we assume JSON mode won't be used at scale, just for testing, and if we're purposefully avoiding breaking changes, I agree the current approach is the best one.

Then, we can backlog Mikhail (@oo-sleeper)'s suggestion for the next time we want to do a breaking release.

Comment thread config/config.go
Comment thread pkg/transform/engine/engine_javascript.go Outdated
Comment thread pkg/transform/engine/engine_javascript.go
Comment thread pkg/transform/engine/engine_javascript.go Outdated
Comment thread pkg/transform/engine/engine_javascript_test.go
Comment thread pkg/transform/engine/engine_javascript_test.go Outdated
Comment thread pkg/transform/engine/engine_javascript_test.go Outdated
@oo-sleeper
Mikhail (oo-sleeper) force-pushed the feat-add-json-mode-to-transformations branch 2 times, most recently from b89fd47 to 3bd0e8a Compare August 8, 2025 15:54
Comment thread pkg/transform/engine/engine_javascript_test.go
Comment thread pkg/transform/engine/engine_javascript_test.go
@oo-sleeper
Mikhail (oo-sleeper) force-pushed the feat-add-json-mode-to-transformations branch from 95e5daa to 906ef7a Compare August 12, 2025 10:35

@colmsnowplow colmsnowplow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Please Rename PR and clean up/give it an accurate commit name once you're done.

@oo-sleeper Mikhail (oo-sleeper) changed the title feat: Add snowplow_mode_v2 to JS transformation feat: Add json_mode to JS transformation Aug 14, 2025
revert changes made to JQ transformation

update code as per ticket discussion; update tests

fix config tests

address comments

clecar up SpModeV2 tests; disable interState for SpModeV2

remove config update

cleanup the test

update test case

improve tests

fix test

revert back to json_mode only
@oo-sleeper
Mikhail (oo-sleeper) force-pushed the feat-add-json-mode-to-transformations branch from 60dd911 to 34dde3c Compare August 14, 2025 09:27
@oo-sleeper
Mikhail (oo-sleeper) merged commit 1301e79 into develop Aug 14, 2025
5 checks passed
@oo-sleeper
Mikhail (oo-sleeper) deleted the feat-add-json-mode-to-transformations branch August 14, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants