### Install json-2-csv CLI Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Installs the command-line interface (CLI) tool for json-2-csv. This allows you to use the conversion functionality directly from your terminal. ```bash npm install @mrodrig/json-2-csv-cli ``` -------------------------------- ### Install json-2-csv Module Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Installs the json-2-csv Node.js package using npm. This is the primary package for using the library in your JavaScript projects. ```bash npm install json-2-csv ``` -------------------------------- ### json-2-csv: Synchronous and Asynchronous JSON to CSV Conversion Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_4_to_5.md Demonstrates synchronous and asynchronous methods for converting JSON data to CSV format using the json-2-csv Node.js library. The example shows how to import the module and perform conversions, highlighting the shift towards synchronous operations in recent versions. ```javascript const converter = require('json-2-csv'); // Synchronous: const csv = converter.json2csv([ { level: 'info', message: 'Our first test' }]); console.log('First output is', csv); // Asynchronous: async function runConversion() { return converter.json2csv([ { level: 'info', message: 'Another test...' }]); } async function runAsync() { const csv = await runConversion(); console.log('Second output is', csv); } runAsync(); console.log('This can run before the second output appears...'); ``` -------------------------------- ### CSV Output Example Source: https://github.com/mrodrig/json-2-csv/wiki/FAQ Illustrates the resulting CSV output when using the json-2-csv converter with the specified keys ('info.name', 'year'). This shows the structure and data transformation. ```csv info.name,year Mike,Sophomore John,Senior Joe,Freshman ``` -------------------------------- ### JSON to CSV CLI Command Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Example of using the json2csv command-line interface to convert a JSON file to a CSV file. This example includes options for writing (W), selecting specific keys (-k), and specifying the output file. ```bash json2csv test.json -o output.csv -W -k arrayOfStrings -o output.csv ``` -------------------------------- ### CSV to JSON CLI Command Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Example of using the csv2json command-line interface to convert a CSV file to a JSON file. It specifies the input CSV file and the output JSON file. ```bash csv2json test.csv -o output.json ``` -------------------------------- ### Advanced CSV to JSON Conversion with Options Source: https://github.com/mrodrig/json-2-csv/wiki/csv2json-Documentation Illustrates advanced CSV to JSON conversion using custom options for delimiters, trimming, and key mapping. This example demonstrates how to configure the converter for specific CSV formats and desired JSON output. ```javascript let converter = require('json-2-csv'); let options = { delimiter : { wrap : '"', // Double Quote (") character field : ',', // Comma field delimiter eol : '\n' // Newline delimiter }, trimHeaderFields : true, trimFieldValues : true, keys : ['Make', 'Model', 'Year', 'Specifications.Mileage', 'Specifications.Trim'] }; let csv = 'Make,Model,Year,Specifications.Mileage,Specifications.Trim\n' + 'Nissan, Murano ,2013,"7,106",\n' + // Note: additional spacing around 'Murano' value 'BMW,X5,2014,"3,287",M\n'; // Note: comma inside the mileage value: "3,287" let csv2jsonCallback = function (err, json) { if (err) throw err; console.log(typeof json); console.log(json.length); console.log(json); } converter.csv2json(csv, csv2jsonCallback, options); ``` -------------------------------- ### Configuration Option Key Changes Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_2_to_3.md Lists the renamed configuration option keys for json-2-csv v3.0.0. Developers must update their code to use the new lower-case keys as uppercase keys are no longer supported. ```APIDOC Configuration Option Key Mappings (v2 -> v3): EMPTY_FIELD_VALUE --> emptyFieldValue CHECK_SCHEMA_DIFFERENCES --> checkSchemaDifferences KEYS --> keys PARSE_CSV_NUMBERS --> parseCsvNumbers SORT_HEADER --> sortHeader TRIM_FIELD_VALUES --> trimFieldValues TRIM_HEADER_FIELDS --> trimHeaderFields PREPEND_HEADER --> prependHeader DELIMITER.FIELD --> delimiter.field DELIMITER.WRAP --> delimiter.wrap DELIMITER.EOL --> delimiter.eol ``` -------------------------------- ### Import json-2-csv in TypeScript Source: https://github.com/mrodrig/json-2-csv/wiki/Using-with-Compiled-JavaScript-Languages Demonstrates how to import the json-2-csv converter module into a TypeScript project. This is the standard way to begin using the library's functionality within a typed JavaScript environment. ```typescript import * as converter from 'json-2-csv'; ``` -------------------------------- ### Promisified Function Name Changes Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_2_to_3.md The names of the promisified functions have been updated to align with industry best practices. `json2csvPromisified` is now `json2csvAsync`, and `csv2jsonPromisified` is now `csv2jsonAsync`. ```APIDOC Asynchronous Function Renaming: - `json2csvPromisified` --> `json2csvAsync` - `csv2jsonPromisified` --> `csv2jsonAsync` - These changes reflect industry best practices for asynchronous operations. ``` -------------------------------- ### Advanced json-2-csv Conversion Example Source: https://github.com/mrodrig/json-2-csv/wiki/json2csv-Documentation This JavaScript snippet demonstrates how to use the `json-2-csv` library to convert an array of JSON objects into a CSV string. It highlights custom options for delimiters, header preparation, and field trimming, along with specifying which keys to include in the output. ```javascript let converter = require('json-2-csv'); let options = { delimiter : { wrap : '"', // Double Quote (") character field : ',', // Comma field delimiter eol : '\n' // Newline delimiter }, prependHeader : true, sortHeader : false, excelBOM : true, trimHeaderValues : true, trimFieldValues : true, keys : ['Make', 'Model', 'Year', 'Specifications.Mileage', 'Specifications.Trim'] }; let documents = [ { Make: 'Nissan', Model: ' Murano ', // Note: This value has additional padding which can be trimmed Year: '2013', Specifications: { Mileage: '7,106', Trim: '' // Note: This value has been changed from the previous example } }, { Make: 'BMW', Model: 'X5', Year: '2014', Specifications: { Mileage: '3,287', Trim: 'M' } } ]; let json2csvCallback = function (err, csv) { if (err) throw err; console.log(csv); }; converter.json2csv(documents, json2csvCallback, options); ``` -------------------------------- ### Promise Flow Naming Changes Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_3_to_4.md This snippet details the renaming of asynchronous functions in the json-2-csv library when migrating from version 3 to version 4. The callback-based flows have been removed, and Promise-based functions have been consolidated. ```javascript Old Function Name --> New Function Name json2csv (using callback) --> (dropped from module) json2csvAsync --> json2csv json2csvPromisified --> json2csv csv2json (using callback) --> (dropped from module) csv2jsonAsync --> csv2json csv2jsonPromisified --> csv2json ``` -------------------------------- ### RFC 4180 Compliance Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_2_to_3.md Version 3.0.0 is now compliant with RFC 4180, improving compatibility with spreadsheet applications like Microsoft Excel. This may require updates for tools that relied on the previous CSV format. ```APIDOC RFC 4180 Compliance: - Enabled by default in v3.0.0. - Improves compatibility with spreadsheet software (e.g., Microsoft Excel). - Potential impact: Applications dependent on the older CSV format may need adjustments. ``` -------------------------------- ### Schema Difference Check Default Change Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_2_to_3.md The default behavior for schema difference checking has changed. By default, it is now disabled. To enforce schema consistency, developers must explicitly set `checkSchemaDifferences: true`. ```APIDOC Schema Difference Check: - Default: Disabled (previously enabled). - To enable: Pass `{ checkSchemaDifferences: true }` in the options object. - Purpose: Ensures all documents in the input have the same schema. ``` -------------------------------- ### Array Delimiter Option Removal Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_2_to_3.md The array delimiter option has been removed in v3.0.0. Instead, arrays and objects are exported as their stringified representation using JSON.stringify for improved compatibility and data interpretation. ```APIDOC Array Delimiter Option: - Removed in v3.0.0. - Replaced by stringifying arrays/objects via JSON.stringify. - Prior to v3.0.0, the array delimiter had to differ from the field delimiter. ``` -------------------------------- ### Excel Byte Order Mark (BOM) Support Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_2_to_3.md A new option `excelBOM` is available to prepend a Byte Order Mark (BOM) to CSV files. This ensures proper display of non-ASCII characters when opening UTF-8 encoded CSVs in Microsoft Excel. ```APIDOC excelBOM Option: - Usage: `excelBOM: true` - Functionality: Prepends a Byte Order Mark (BOM) to the CSV output. - Benefit: Allows Microsoft Excel to correctly open UTF-8 CSV files with non-ASCII characters. - Note: Not required for applications like Apple's Numbers. ``` -------------------------------- ### Unwinding Arrays in JSON to CSV Conversion Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Demonstrates how the `unwindArrays` option affects CSV output when converting JSON with nested arrays. Shows examples for both enabling (`true`) and disabling (`false`) the feature, illustrating how array elements are handled. ```JSON [ { "_id": {"$oid": "5cf7ca3616c91100018844af"}, "data": {"category": "Computers", "options": [{"name": "MacBook Pro 15"}, {"name": "MacBook Air 13"}]} }, { "_id": {"$oid": "5cf7ca3616c91100018844bf"}, "data": {"category": "Cars", "options": [{"name": "Supercharger"}, {"name": "Turbocharger"}]} } ] ``` ```CSV _id.$oid,data.category,data.options.name 5cf7ca3616c91100018844af,Computers,MacBook Pro 15 5cf7ca3616c91100018844af,Computers,MacBook Air 13 5cf7ca3616c91100018844bf,Cars,Supercharger 5cf7ca3616c91100018844bf,Cars,Turbocharger ``` ```CSV _id.$oid,data.category,data.options 5cf7ca3616c91100018844af,Computers,"[{ ""name"": ""MacBook Pro 15""},{""name"": ""MacBook Air 13""}]" 5cf7ca3616c91100018844bf,Cars,"[{ ""name"": ""Supercharger""},{""name"": ""Turbocharger""}]" ``` -------------------------------- ### Deep CSV Conversion with expandArrayObjects Source: https://github.com/mrodrig/json-2-csv/blob/main/upgrade_guides/UPGRADE_2_to_3.md The `expandArrayObjects` option (v3.2.0) enables deep conversion of objects within array values. This flattens nested structures into CSV headers, though it may alter the JSON structure upon reverse conversion. ```javascript // Example of expandArrayObjects option // Input JSON: // { // "id": "123", // "list": [ // {"a": "a"}, // {"b": "b"} // ] // } // With expandArrayObjects: true, output CSV might look like: // id,list.a,list.b // 123,a,b // // Limitation: Reverse conversion (CSV to JSON) may result in a different document structure due to key generation differences. ``` -------------------------------- ### Project Tests Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Commands to run project tests and check test coverage using npm. ```bash $ npm test To see test coverage, please run: $ npm run coverage ``` -------------------------------- ### Basic JavaScript Usage Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Demonstrates the basic usage of the json-2-csv module in a Node.js environment. It shows how to import the converter and use the json2csv function with await. ```javascript let converter = require('json-2-csv'); const csv = await converter.json2csv(data, options); ``` -------------------------------- ### Convert JSON to CSV with Specific Keys (JavaScript) Source: https://github.com/mrodrig/json-2-csv/wiki/FAQ Demonstrates how to use the json-2-csv library to convert an array of JSON objects into a CSV string. It shows how to specify which keys to include in the output CSV by using the `options.keys` parameter. ```javascript let converter = require('json-2-csv'); let options = { keys : ['info.name', 'year'] }; let documents = [ { "info": { "name": "Mike" }, "coursesTaken": ["CS2500", "CS2510"], "year": "Sophomore" }, { "info": { "name": "John" }, "coursesTaken": ["ANTH1101", "POL2312", "MATH2142", "POL3305", "LAW2100"], "year": "Senior" }, { "info": { "name": "Joe" }, "coursesTaken": [], "year": "Freshman" } ]; converter.json2csv(documents, function (err, csv) { if (err) { throw err; } return console.log(csv); }, options); ``` -------------------------------- ### Convert CSV to JSON using Callback Source: https://github.com/mrodrig/json-2-csv/wiki/csv2json-Documentation Demonstrates the basic usage of the csv2json function with a callback to handle the conversion result. It takes CSV data and a callback function as arguments, processing the conversion asynchronously. ```javascript let converter = require('json-2-csv'); let csv = "Make,Model,Year,Specifications.Mileage,Specifications.Trim\n" + "Nissan,Murano,2013,7106,S AWD\n" + "BMW,X5,2014,3287,M\n"; let csv2jsonCallback = function (err, json) { if (err) throw err; console.log(typeof json); console.log(json.length); console.log(json); } converter.csv2json(csv, csv2jsonCallback); ``` -------------------------------- ### json2csv CLI Usage Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Command-line interface for converting JSON files to CSV. It supports various options for output, delimiters, schema checking, key selection, and data transformation. ```bash Usage: json2csv [options] Arguments: jsonFile JSON file to convert Options: -V, --version output the version number -o, --output [output] Path of output file. If not provided, then stdout will be used -a, --array-indexes-as-keys Includes array indexes in the generated keys -S, --check-schema Check for schema differences -f, --field Field delimiter -w, --wrap Wrap delimiter -e, --eol End of Line delimiter -E, --empty-field-value Empty field value -n, --expand-nested-objects Expand nested objects to be deep converted to CSV -k, --keys [keys] Keys of documents to convert to CSV -d, --escape-header-nested-dots Escape header nested dots -b, --excel-bom Excel Byte Order Mark character prepended to CSV -x, --exclude-keys [keys] Comma separated list of keys to exclude -A, --expand-array-objects Expand array objects -W, --without-header Withhold the prepended header -p, --prevent-csv-injection Prevent CSV Injection -s, --sort-header Sort the header fields -F, --trim-fields Trim field values -H, --trim-header Trim header fields -U, --unwind-arrays Unwind array values to their own CSV line -I, --iso-date-format Use ISO 8601 date format -L, --locale-format Use locale format for values -B, --wrap-booleans Wrap booleans -h, --help display help for command ``` -------------------------------- ### csv2json CLI Usage Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Command-line interface for converting CSV files to JSON. It allows specifying input files and configuring options such as delimiters, BOM handling, and field trimming. ```bash Usage: csv2json [options] Arguments: csvFile CSV file to convert Options: -V, --version output the version number -o, --output [output] Path of output file. If not provided, then stdout will be used -f, --field Field delimiter -w, --wrap Wrap delimiter -e, --eol End of Line delimiter -b, --excel-bom Excel Byte Order Mark character prepended to CSV -p, --prevent-csv-injection Prevent CSV Injection -F, --trim-fields Trim field values -H, --trim-header Trim header fields -h, --header-fields Specify the fields names in place a header line in the CSV itself -k, --keys [keys] Keys of documents to convert to CSV --help display help for command ``` -------------------------------- ### ESM JavaScript Usage Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Shows how to import the json2csv function using ES Module syntax, which is common in modern JavaScript development. ```javascript import { json2csv } from 'json-2-csv'; ``` -------------------------------- ### APIDOC: json2csv Configuration Options Source: https://github.com/mrodrig/json-2-csv/wiki/json2csv-Documentation Details the various options available to customize the JSON to CSV conversion process. These options control aspects like schema validation, delimiters, field formatting, and header generation. ```APIDOC json2csv(array, callback, options) json2csvAsync(array, options) Parameters: array: An array of JSON documents to be converted to CSV. callback: A function of the form `function (err, csv)` for the synchronous version. options: (Optional) A JSON document specifying configuration key-value pairs. Options: checkSchemaDifferences: Boolean - If true, throws an error if documents have differing schemas. Default: false. delimiter: Object - Specifies different types of delimiters. field: String - Field Delimiter. Default: `,`. wrap: String - Wrap values in the delimiter of choice (e.g., quotes). Default: `"`. eol: String - End of Line Delimiter. Default: `\n`. emptyFieldValue: Any - Value substituted for `undefined`, `null`, or empty string fields. Default: none. excelBOM: Boolean - Prepends a unicode character for Excel compatibility with UTF-8. Default: false. expandArrayObjects: Boolean - If true, deep-converts objects within array values to CSV keys (e.g., `specifications.features`). If false, uses the array key itself (e.g., `specifications`). Default: false. Example: Input: `[{ "specifications": [ { "features": [...] }, { "mileage": "5000" } ] }]` `expandArrayObjects: true` -> Keys: `['specifications.features', 'specifications.mileage']` `expandArrayObjects: false` -> Keys: `['specifications']` keys: Array - Specify keys (as strings) to convert. Use dot notation for nested objects (e.g., `['info.name']`). If null or omitted, all keys are converted. Default: null. prependHeader: Boolean - Prepends the auto-generated header as the first line. Default: true. sortHeader: Boolean - Sorts header keys alphabetically. Default: false. trimHeaderFields: Boolean - Trims whitespace from header fields. Default: false. trimFieldValues: Boolean - Trims whitespace from field values. (*in development*). Default: false. ``` -------------------------------- ### JavaScript Usage: json2csv Callback API Source: https://github.com/mrodrig/json-2-csv/wiki/json2csv-Documentation Demonstrates the basic usage of the json2csv function with a callback to handle the conversion result or errors. This method is suitable for scenarios where immediate asynchronous handling is preferred. ```javascript let converter = require('json-2-csv'); let documents = [ { Make: 'Nissan', Model: 'Murano', Year: '2013', Specifications: { Mileage: '7106', Trim: 'S AWD' } }, { Make: 'BMW', Model: 'X5', Year: '2014', Specifications: { Mileage: '3287', Trim: 'M' } } ]; let json2csvCallback = function (err, csv) { if (err) throw err; console.log(csv); }; converter.json2csv(documents, json2csvCallback); ``` -------------------------------- ### JavaScript Usage: json2csv Async API (Promises) Source: https://github.com/mrodrig/json-2-csv/wiki/json2csv-Documentation Illustrates the use of the json2csvAsync function, which returns a Promise for handling JSON to CSV conversion. This approach is preferred for modern JavaScript development using async/await or Promise chaining. ```javascript let converter = require('json-2-csv'); let documents = [ { Make: 'Nissan', Model: 'Murano', Year: '2013', Specifications: { Mileage: '7106', Trim: 'S AWD' } }, { Make: 'BMW', Model: 'X5', Year: '2014', Specifications: { Mileage: '3287', Trim: 'M' } } ]; converter.json2csvAsync(documents) .then(console.log) .catch((err) => console.log('ERROR: ' + err.message)); ``` -------------------------------- ### Convert CSV to JSON using Promises Source: https://github.com/mrodrig/json-2-csv/wiki/csv2json-Documentation Shows how to use the csv2jsonAsync function for promise-based CSV to JSON conversion. This method returns a Promise that resolves with the JSON array or rejects with an error. ```javascript let converter = require('json-2-csv'); let csv = "Make,Model,Year,Specifications.Mileage,Specifications.Trim\n" + "Nissan,Murano,2013,\"7,106\",S AWD\n" + "BMW,X5,2014,\"3,287\",M\n"; converter.csv2jsonAsync(csv) .then(console.log) .catch((err) => console.log('ERROR: ' + err.message)); ``` -------------------------------- ### json2csv Function and Options Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md The core function for converting JSON arrays to CSV strings. It accepts an array of JSON objects and an optional configuration object to customize the output. ```APIDOC json2csv(array, options) => string Converts an array of JSON documents to a CSV string or rejects with an Error. Parameters: array: An array of JSON documents to be converted to CSV. options: (Optional) A JSON document specifying conversion options. Options Object: arrayIndexesAsKeys: Boolean Description: Should array indexes be included in the generated keys? Default: false Note: Provides a more accurate representation of the JSON in the returned CSV, but may be less human readable. See #207 for more details. checkSchemaDifferences: Boolean Description: Should all documents have the same schema? Default: false Note: An error will be thrown if some documents have differing schemas when this is set to true. delimiter: Object Description: Specifies the different types of delimiters. Properties: field: String Description: Field Delimiter. Default: "," wrap: String Description: Wrap values in the delimiter of choice (e.g. wrap values in quotes). Default: "\"" eol: String Description: End of Line Delimiter. Default: "\n" emptyFieldValue: Any Description: Value that, if specified, will be substituted in for field values that are undefined, null, or an empty string. Default: none escapeHeaderNestedDots: Boolean Description: Should nested dots in header keys be escaped? Default: true Example: Input JSON: [ { "a.a": "1" } ] true will generate: a\.a 1 false will generate: a.a 1 Note: This may result in CSV output that does not map back exactly to the original JSON. excelBOM: Boolean Description: Should a unicode character be prepended to allow Excel to open a UTF-8 encoded file with non-ASCII characters present. excludeKeys: Array Description: Specify the string keys or RegExp patterns that should be excluded from the output. Provided string keys will also be used as a RegExp to help exclude keys under a specified prefix, such as all keys of Objects in an Array when expandArrayObjects is true (e.g., providing 'baz' will exclude 'baz.a' too). Default: [] Note: When used with unwindArrays, arrays present at excluded key paths will not be unwound. expandNestedObjects: Boolean Description: Should nested objects be deep-converted to CSV? Default: true Example: Input JSON: [ { "make": "Nissan", "model": "Murano", "year": 2013, "specifications": { "mileage": 7106, "trim": "S AWD" } } ] true uses the following keys: ['make', 'model', 'year', 'specifications.mileage', 'specifications.trim'] false uses the following keys: ['make', 'model', 'year', 'specifications'] Note: This may result in CSV output that does not map back exactly to the original JSON. expandArrayObjects: Boolean Description: Should objects in array values be deep-converted to CSV? Default: false Example: Input JSON: [ { "specifications": [ { "features": [...] }, { "mileage": "5000" } ] } ] true uses the following keys: ['specifications.features', 'specifications.mileage'] false uses the following keys: ['specifications'] Note: This may result in CSV output that does not map back exactly to the original JSON. See #102 for more information. keys: Array Description: Specify the keys that should be converted. These will be auto-detected from your data by default. Keys can either be specified as a String representing the key path that should be converted, or as an Object of the following format: { "field": "string", // required "title": "string", // optional "wildcardMatch": false, // optional - default: false } When specifying keys as an Object, the `field` property specifies the key path, while `title` specifies a more human readable field heading. Additionally, the `wildcardMatch` option allows you to optionally specify that all auto-detected fields with the specified field prefix should be included in the CSV. The list specified can contain a combination of Objects and Strings. Examples: [ 'key1', 'key2', ... ] [ 'key1', { field: 'key2', wildcardMatch: true }] [ { field: 'key1', title: 'Key 1' }, { field: 'key2' }, 'key3', ... ] Key Paths - If you are converting a nested object (ie. {info : {name: 'Mike'}}), then set this to ['info.name'] parseValue: Function Description: Specify how values should be converted into CSV format. This function is provided a single field value at a time and must return a String. The built-in parsing method is provided as the second argument for cases where default parsing is preferred. ``` -------------------------------- ### csv2json Function Documentation Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md Details the csv2json JavaScript function for converting CSV strings to JSON object arrays. It outlines parameters for input CSV, optional configuration options like delimiters, header handling, value parsing, and trimming. ```APIDOC csv2json(csv, options) => object[] Returns the JSON object array (object[]) or rejects with an Error if there was an issue. Parameters: csv - A string of CSV options - (Optional) A JSON document specifying any of the following key value pairs: delimiter - Document - Specifies the different types of delimiters field - String - Field Delimiter. Default: `,` wrap - String - The character that field values are wrapped in. Default: `"` eol - String - End of Line Delimiter. Default: `\n` excelBOM - Boolean - Does the CSV contain a unicode character prepended in order to allow Excel to open a UTF-8 encoded file with non-ASCII characters present? Default: false headerFields - Array - Specify the field names (as strings) in place of a header line in the CSV itself. Default: Parses the header fields directly from the CSV string. If you want to generate a nested object (ie. {info : {name: 'Mike'}}), then use `.` characters in the string to denote a nested field, like ['info.name']. If your CSV has a header line included, then don't specify the option to utilize the default values that will be parsed from the CSV. keys - Array - Specify the keys (as strings) that should be converted. Default: null. If you have a nested object (ie. {info : {name: 'Mike'}}), then set this to `['info.name']`. If you want all keys to be converted, then specify null or don't specify the option to utilize the default. parseValue - Function - Specify how `String` representations of field values should be parsed when converting back to JSON. This function is provided a single `String` and can return any value. Default: `JSON.parse` - An attempt is made to convert the String back to its original value using `JSON.parse`. trimHeaderFields - Boolean - Should the header fields be trimmed? Default: false trimFieldValues - Boolean - Should the field values be trimmed? Default: false ``` -------------------------------- ### json-2-csv Module Functionality Source: https://github.com/mrodrig/json-2-csv/blob/main/README.md APIDOC for the json-2-csv Node.js module. This module converts an array of JSON documents to a CSV string and vice-versa. Column headings are generated from JSON keys, and nested documents use '.' notation. CSV input requires consistent values per line. ```APIDOC json2csv(data: Array, options?: Object): Promise Converts an array of JSON objects into a CSV string. - data: An array of JSON objects to convert. - options: Optional configuration object for customization (e.g., delimiters, headers). - Returns: A Promise that resolves to the CSV string. csv2json(data: string, options?: Object): Promise> Converts a CSV string into an array of JSON objects. - data: The CSV string to convert. - options: Optional configuration object for customization (e.g., delimiters, headers). - Returns: A Promise that resolves to an array of JSON objects. Key Features: - Automatic column heading generation from JSON keys. - Handles nested JSON objects by concatenating keys with '.'. - CSV input must have the same number of values per line. - Supports custom delimiters and other options via the options object. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.