Hi,
Is there a way to convert snake_case column names to camelCase when outputting JSON.
I can use SQL similar to the following, but wondered if there was a more generic way in ORDS so I do not have to set up custom code whenever I need to output camelCase field names. As far as I can tell by default ORDS uses snake_case, and if I just set the column aliases to camelCase, it does a LOWER on them.
My code,
WITH cols AS
(
SELECT LOWER(column_name) col_name
FROM user_tab_columns
WHERE table_name = 'MY_TABLE'
ORDER BY column_id
)
SELECT col_name
, LOWER(SUBSTR(REPLACE(INITCAP(REPLACE(col_name,'_',' ')),' ',''),1,1)) || SUBSTR(REPLACE(INITCAP(REPLACE(col_name,'_',' ')),' ',''),2) camel_case
FROM cols
It is a shame there is not a function CAMEL, similar to INITCAP, UPPER, LOWER, which converts to camelCase, especially as this is recognised as a "standard" for JSON.