Question about datamapper

12 views
Skip to first unread message

Stephen Paul Weber

unread,
Feb 19, 2024, 8:43:47 PMFeb 19
to prosody-dev
I'm trying to use datamapper for something a bit more advanced than I've done before, and I'm not sure if it's possible or not so I thought I'd ask about it.  Here is the JSON input:

{ "alias": "GlitchTip", "text": "GlitchTip Alert", "attachments": [ { "title": "Some Cool Error", "title_link": "https://example.com/some-cool-link", "text": "/inbound/calls" } ] }

And I want to map it to an Atom structure like this:

<entry>
<title>Some Cool Error</title>
<content type="text">/inbound/calls</content>
<link rel="alternate" type="text/html" href="https://example.com/some-cool-link" />
</entry>

The basic issue I'm running into is that because attachments is an array, datamapper wants to wrap each element of the array in a tag.  I'd like everything from every element of the array (of which there happens to only ever be one) to go onto the parent <entry> tag.  I've looked at the code a bit and I think this might just not be something the datamapper format can describe, but thought I'd ask here if I maybe missed something.

Thanks.

Kim Alvefur

unread,
Feb 20, 2024, 11:23:44 AMFeb 20
to proso...@googlegroups.com
On Mon, Feb 19, 2024 at 05:43:47PM -0800, Stephen Paul Weber wrote:
>Here is the JSON input:
>
>{ "alias": "GlitchTip", "text": "GlitchTip Alert", "attachments": [ {
>"title": "Some Cool Error", "title_link":
>"https://example.com/some-cool-link", "text": "/inbound/calls" } ] }
>
>And I want to map it to an Atom structure like this:
>
><entry>
><title>Some Cool Error</title>
><content type="text">/inbound/calls</content>
><link rel="alternate" type="text/html"
>href="https://example.com/some-cool-link" />
></entry>
>
>The basic issue I'm running into is that because attachments is an array,
>datamapper wants to wrap each element of the array in a tag. I'd like
>everything from every element of the array (of which there happens to only
>ever be one) to go onto the parent <entry> tag.

I would consider mapping the array items to <entry> and picking them out
of the larger structure before or after the datamapper step.

For more advanced transforms where the input and output are very
different I think something other than util.datamapper would be more
suited, but other than regular Lua code we don't really have anything
for that right now.

--
Zash
Reply all
Reply to author
Forward
0 new messages