Skip to main content
Solved

Creating json message with column alias


Tejo van de Bor
Captain
Forum|alt.badge.img+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?

 

Best answer by Mark Jongeling

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

View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

Mark Jongeling
Administrator
Forum|alt.badge.img+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


Tejo van de Bor
Captain
Forum|alt.badge.img+5

Thanks Mark, I’m gonna try this!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings