I am trying to write a script that dynamically reads all the available columns of a certain table and removes/adds a certain formatting to that column based on some T-SQL functions. I am using an azure Synapse pipeline to lookup/format the available column names via a JSON script and try to copy the data into a parquet file.
When I use the output of the JSON script as input for my column mapping, the step returns an error since parquet does not accept the literal JSON array strings. I would like to remove the escape backslash in the output and pass the column names as strings. Parquet does not accept the backslashes as input for column names.
This is the script i am using as input:
DECLARE @json_construct varchar(MAX) = ''{"type": "TabularTranslator", "mappings": {X}}'';
DECLARE @json VARCHAR(MAX);
SET @json = (
SELECT
''source.name'' = ''['''''' + c.[name] + '''''']''
,''sink.name'' = LOWER(REPLACE(TRIM(REPLACE(c.[name], ''_'', '''')), '' '', ''_''))
FROM sys.tables t
JOIN sys.schemas s ON s.schema_id = t.schema_id
JOIN sys.all_columns c ON c.object_id = t.object_id
JOIN sys.types y ON c.system_type_id = y.system_type_id
AND c.user_type_id = y.user_type_id
WHERE 1 = 1
AND t.[name] = ''',string(pipeline().parameters.table_name),'''
AND s.[name] = ''',string(pipeline().parameters.schema_name),'''
ORDER BY c.column_id
FOR JSON PATH );
SELECT REPLACE(@json_construct,''{X}'', @json) AS json_output;
The problem is situated in the output of the ''sink.name''. Does somebody know how to remove the backslashes in the JSON string so that parquet accepts the column names?
Thank you in advance!



