Convert CSV to JSON

Convert CSV to JSON

Aspose.Cells supports converting CSV to JSON. For this, the API provides ExportRangeToJsonOptions and JsonUtility classes. The ExportRangeToJsonOptions class provides the options for exporting a range to JSON. The ExportRangeToJsonOptions class has the following properties.

  • ExportAsString: Exports the string values of the cells to JSON.
  • HasHeaderRow: Indicates whether the range contains a header row.
  • Indent: Indicates the indentation.

The JsonUtility class exports the JSON using the export options set with the ExportRangeToJsonOptions class.

The following code sample demonstrates the use of ExportRangeToJsonOptions and JsonUtility classes to load the source CSV file and print the JSON output in the console.

Sample Code

Console Output

[
  {
    "id": 1,
    "language": "Java",
    "edition": "third",
    "author": "Herbert Schildt",
    "streetAddress": 126,
    "city": "San Jone",
    "state": "CA",
    "postalCode": 394221
  },
  {
    "id": 2,
    "language": "C++",
    "edition": "second",
    "author": "EAAAA",
    "streetAddress": 126,
    "city": "San Jone",
    "state": "CA",
    "postalCode": 394221
  },
  {
    "id": 3,
    "language": ".NET",
    "edition": "second",
    "author": "E.Balagurusamy",
    "streetAddress": 126,
    "city": "San Jone",
    "state": "CA",
    "postalCode": 394221
  }
]