Java convert text file with data in json format to json file

Viewed 30

I have my text file in JSON format:

data.txt

{
  "name": "My Card Product 01",
  "start_date": "2020-04-27",
  "config": {
    "poi" : {
      "ecommerce" : false,
      "atm" : false,
      "other": {
        "allow": true,
        "card_presence_required": false,
        "cardholder_presence_required": false
      }
    }
  }
}

Is it possible if I can convert that text file to a JSON file? I meant I want to create a JSON file output.json with the same data from data.txt

I tried to work with apose cells:

Workbook workbook = new Workbook("src/main/java/assignment_09_09/data.txt");
workbook.save("src/main/java/assignment_09_09/output.json");

But the "output.json" file is not what I'm expecting. It becomes:

[
 {
  "name": null,
  "start_date": null,
  "config": "poi",
  "Column4": null,
  "Column5": null,
  "Column6": null,
  "Column7": null
 },
 {
  "name": null,
  "start_date": null,
  "config": "ecommerce",
  "Column4": "atm",
  "Column5": "other",
  "Column6": null,
  "Column7": null
 },
 {
  "name": null,
  "start_date": null,
  "config": null,
  "Column4": null,
  "Column5": "allow",
  "Column6": "card_presence_required",
  "Column7": "cardholder_presence_required"
 },
 {
  "name": "My Card Product 01",
  "start_date": "2020-04-27",
  "config": false,
  "Column4": false,
  "Column5": true,
  "Column6": false,
  "Column7": false
 }
]
0 Answers
Related