parseCSV
codebolt.outputparsers.parseCSV(csvString: string): Object
Parses CSV string and returns a result object with success flag and parsed array of objects.
Parameters
Name | Type | Description |
---|---|---|
csvString | string | The CSV string to parse. |
Response Structure
The method returns an object with the following structure:
Success Response
{
success: true,
parsed: [
{ column1: "value1", column2: "value2", ... },
{ column1: "value3", column2: "value4", ... },
...
]
}
Error Response
{
success: false,
error: <Error_object>
}
Examples
Valid CSV Parsing
const csvData = 'name,age,city\nJohn,25,New York\nJane,30,Los Angeles\nBob,35,Chicago';
const result = await codebolt.outputparsers.parseCSV(csvData);
console.log(result);
// Output: {
// success: true,
// parsed: [
// { name: 'John', age: '25', city: 'New York' },
// { name: 'Jane', age: '30', city: 'Los Angeles' },
// { name: 'Bob', age: '35', city: 'Chicago' }
// ]
// }
Simple CSV with Headers
const csvData = 'product,price\nLaptop,999\nMouse,29';
const result = await codebolt.outputparsers.parseCSV(csvData);
console.log(result);
// Output: {
// success: true,
// parsed: [
// { product: 'Laptop', price: '999' },
// { product: 'Mouse', price: '29' }
// ]
// }