Solved

Creating json message with column alias


Userlevel 2
Badge +5

hi, 

When creating json messages for a 3rd party API, we use SQL to create the json structure. This json message has > 100 fields, and most of these fields are in our datamodel. But, of course, our column names do differ from the API fields, so we have to alias these fields in the procedure.

Is there a way to have our column names following the TW naming convention, and register the API field labels? I see columns have alias property in the data domain, can we use this?

 

icon

Best answer by Mark Jongeling 24 June 2022, 15:13

View original

This topic has been closed for comments

2 replies

Userlevel 7
Badge +23

Hi Tejo, 

I suppose you are creating the JSON messages inside Control procedures. Here you have full control over how you combine information from your model. You could make use of the Column alias field, but it may be better to use Tags for this on your columns. This could even be generated automatically using Dynamic model procedure, creating Tags with the column name as default for example, and leaving the generated_by_control_proc_id empty so you can make exceptions for the columns that need it.

Hope that helps!


Example out of the Export project version task:

--Export [TAB]
insert into @data (data_tab_name, json_data)
select '[TAB]',
(select
[COL] as [COL_NAME][COMMA]
from [TAB] t1
for json path)

[TAB] → Table name - tab_id

[COL] → Column name - col_id

[COL_NAME] → Column alias - alias_col_id / tag value

[COMMA] → Add a comma after every row except the last one

Replace these [TEXT] using Control procedure code

Userlevel 2
Badge +5

Thanks Mark, I’m gonna try this!