Example: Using CSV Data in Double Quotation Marks in CSV_TO_JSON - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

CSV data feature fields may be enclosed in double quotation marks. The double quotation marks allow invalid characters (such as record/field delimiters or double quotation marks) in the value itself. In the following example, CSV_TO_JSON omits the extra leading and trailing double quotation marks from the output.

SELECT * FROM CSV_TO_JSON
(
	ON (SELECT 'Item_ID,Item_Name,"Item#Color",Item_Style,Quantity_Purchased,Item_Price,Total_Price#55,bicycle,red,boys,1,100.00,100.00#88,toy boat,pink,,1,15.10,15.10#105,soap,,,1,0.99,0.99')
	USING SCHEMA('{"record_delimiter":"#"}')
) AS csvJSON ORDER BY data."Item_ID";

Result:

> {"Item_ID":"55", "Item_Name":"bicycle", "Item#Color":"red", "Item_Style":"boys", "Quantity_Purchased":"1", "Item_Price":"100.00", "Total_Price":"100.00"}
> {"Item_ID":"88", "Item_Name":"toy boat", "Item#Color":"pink", "Item_Style":null, "Quantity_Purchased":"1", "Item_Price":"15.10", "Total_Price":"15.10"}
> {"Item_ID":"105", "Item_Name":"soap", "Item#Color":null, "Item_Style":null, "Quantity_Purchased":"1", "Item_Price":"0.99", "Total_Price":"0.99"}