Skip to content

Commit

Permalink
feat: The json module is now avaiable to stream maps (#2531)
Browse files Browse the repository at this point in the history
* Add json function to CustomStreamMap

This allows using `json.loads()` and `json.dumps()` to convert fields
between text and json representations.

* docs: Add json function to Stream Maps

* Update docs/stream_maps.md

* Update docs/stream_maps.md

* Update docs/stream_maps.md

* Update docs/stream_maps.md

---------

Co-authored-by: Edgar Ramírez Mondragón <[email protected]>
  • Loading branch information
grigi and edgarrmondragon authored Jul 16, 2024
1 parent 7a3f42a commit 8348456
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/stream_maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ can be referenced directly by mapping expressions.
`hashlib.md5(<input>.encode("utf-8")).hexdigest()`.
- `datetime` - This is the datetime module object from the Python standard library. You can access
datetime.datetime, datetime.timedelta, etc.
- [`json`](inv:python:py:module:#json) - This is the json module object from the Python standard
library. Primarily used for calling [`json.dumps()`](inv:python:py:function:#json.dumps)
and [`json.loads()`](inv:python:py:function:#json.loads).

#### Built-in Variable Names

Expand Down
2 changes: 2 additions & 0 deletions singer_sdk/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fnmatch
import hashlib
import importlib.util
import json
import logging
import typing as t

Expand Down Expand Up @@ -306,6 +307,7 @@ def functions(self) -> dict[str, t.Callable]:
funcs["md5"] = md5
funcs["datetime"] = datetime
funcs["bool"] = bool
funcs["json"] = json
return funcs

def _eval(
Expand Down

0 comments on commit 8348456

Please sign in to comment.