Skip to content

Commit 08c5e00

Browse files
Anto-tech-antoiuccio
authored andcommitted
update documentation
1 parent bfcdb56 commit 08c5e00

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ show your :heart: and support.
2929
- [Support for NodeJS, Browser, JS, TS](#support-for-nodejs-browser-js-ts)
3030
- [Prerequisites](#prerequisites)
3131
- [Install npm *convert-csv-to-json package*](#install-npm-convert-csv-to-json-package)
32-
* [Sync API Usage](#sync-api-usage)
33-
+ [Generate JSON file](#generate-json-file)
34-
+ [Generate Array of Object in JSON format](#generate-array-of-object-in-json-format)
35-
+ [Generate Object with sub array](#generate-object-with-sub-array)
36-
+ [Define field delimiter](#define-field-delimiter)
37-
+ [Trim header field](#trim-header-field)
38-
+ [Trim header field with whitespaces](#trim-header-field-with-whitespaces)
39-
+ [Support Quoted Fields](#support-quoted-fields)
40-
+ [Index header](#index-header)
41-
+ [Empty rows](#empty-rows)
42-
+ [Format property value by type](#format-property-value-by-type)
43-
- [Numbers](#numbers)
44-
- [Boolean](#boolean)
45-
- [Complete Example](#complete-example)
46-
+ [Encoding](#encoding)
47-
+ [Working with CSV strings directly](#working-with-csv-strings-directly)
32+
- [Sync API Usage](#sync-api-usage)
33+
* [Generate JSON file](#generate-json-file)
34+
* [Generate Array of Object in JSON format](#generate-array-of-object-in-json-format)
35+
* [Generate Object with sub array](#generate-object-with-sub-array)
36+
* [Define field delimiter](#define-field-delimiter)
37+
* [Trim header field](#trim-header-field)
38+
* [Trim header field with whitespaces](#trim-header-field-with-whitespaces)
39+
* [Support Quoted Fields](#support-quoted-fields)
40+
* [Index header](#index-header)
41+
* [Empty rows](#empty-rows)
42+
* [Format property value by type](#format-property-value-by-type)
43+
+ [Numbers](#numbers)
44+
+ [Boolean](#boolean)
45+
+ [Complete Example](#complete-example)
46+
* [Encoding](#encoding)
47+
* [Working with CSV strings directly](#working-with-csv-strings-directly)
4848
* [Sync API (TypeScript)](#sync-api-typescript)
4949
- [Browser API Usage](#browser-api-usage)
5050
* [Basic Browser Operations](#basic-browser-operations)
@@ -145,9 +145,9 @@ Install package on your machine
145145
$ npm install -g convert-csv-to-json
146146
```
147147

148-
### Sync API Usage
148+
## Sync API Usage
149149

150-
#### Generate JSON file
150+
### Generate JSON file
151151
```js
152152
let csvToJson = require('convert-csv-to-json');
153153

@@ -156,7 +156,7 @@ let fileOutputName = 'myOutputFile.json';
156156

157157
csvToJson.generateJsonFileFromCsv(fileInputName,fileOutputName);
158158
```
159-
#### Generate Array of Object in JSON format
159+
### Generate Array of Object in JSON format
160160
```js
161161
let csvToJson = require('convert-csv-to-json');
162162

@@ -166,7 +166,7 @@ for(let i=0; i<json.length;i++){
166166
}
167167
```
168168

169-
#### Generate Object with sub array
169+
### Generate Object with sub array
170170
```
171171
firstName;lastName;email;gender;age;birth;sons
172172
Constantin;Langsdon;[email protected];Male;96;10.02.1965;*diego,marek,dries*
@@ -193,7 +193,7 @@ The result will be:
193193
]
194194
```
195195

196-
#### Define field delimiter
196+
### Define field delimiter
197197
A field delimiter is needed to split the parsed values. As default the field delimiter is the **semicolon** (**;**), this means that during the parsing when a **semicolon (;)** is matched a new JSON entry is created.
198198
In case your CSV file has defined another field delimiter you have to call the function ```fieldDelimiter(myDelimiter)``` and pass it as parameter the field delimiter.
199199

@@ -204,11 +204,11 @@ E.g. if your field delimiter is the comma **,** then:
204204
.getJsonFromCsv(fileInputName);
205205
```
206206

207-
#### Trim header field
207+
### Trim header field
208208

209209
The content of the field header is cut off at the beginning and end of the string. E.g. " Last Name " -> "Last Name".
210210

211-
#### Trim header field with whitespaces
211+
### Trim header field with whitespaces
212212

213213
Use the method *trimHeaderFieldWhiteSpace(true)* to remove the whitespaces in an header field (E.g. " Last Name " -> "LastName"):
214214

@@ -217,7 +217,7 @@ Use the method *trimHeaderFieldWhiteSpace(true)* to remove the whitespaces in an
217217
.getJsonFromCsv(fileInputName);
218218
```
219219

220-
#### Support Quoted Fields
220+
### Support Quoted Fields
221221
To be able to parse correctly fields wrapped in quote, like the **last_name** in the first row in the following example:
222222

223223
|first_name| last_name |email|
@@ -242,18 +242,18 @@ The result will be:
242242
]
243243
```
244244

245-
#### Index header
245+
### Index header
246246
If the header is not on the first line you can define the header index like:
247247

248248
```js
249249
csvToJson.indexHeader(3)
250250
.getJsonFromCsv(fileInputName);
251251
```
252252

253-
#### Empty rows
253+
### Empty rows
254254
Empty rows are ignored and not parsed.
255255

256-
#### Format property value by type
256+
### Format property value by type
257257
The `formatValueByType()` function intelligently converts string values to their appropriate types while preserving data integrity. To enable automatic type conversion:
258258

259259
```js
@@ -263,7 +263,7 @@ csvToJson.formatValueByType()
263263

264264
This conversion follows these rules:
265265

266-
##### Numbers
266+
#### Numbers
267267
- Regular integers and decimals are converted to Number type
268268
- Numbers with leading zeros are preserved as strings (e.g., "0012" stays "0012")
269269
- Large integers outside JavaScript's safe range are preserved as strings
@@ -279,7 +279,7 @@ For example:
279279
}
280280
```
281281

282-
##### Boolean
282+
#### Boolean
283283
Case-insensitive "true" or "false" strings are converted to boolean values:
284284
```json
285285
{
@@ -288,7 +288,7 @@ Case-insensitive "true" or "false" strings are converted to boolean values:
288288
}
289289
```
290290

291-
##### Complete Example
291+
#### Complete Example
292292
Input CSV:
293293
```csv
294294
first_name;last_name;email;gender;age;id;zip;registered
@@ -322,7 +322,7 @@ Output JSON:
322322
]
323323
```
324324

325-
#### Encoding
325+
### Encoding
326326
You can read and decode files with the following encoding:
327327
* utf8:
328328
```js
@@ -360,7 +360,7 @@ You can read and decode files with the following encoding:
360360
.getJsonFromCsv(fileInputName);
361361
```
362362

363-
#### Working with CSV strings directly
363+
### Working with CSV strings directly
364364
If you have CSV content as a string (for example, from an API response or test data), you can parse it directly without writing to a file:
365365

366366
```js

0 commit comments

Comments
 (0)