0

How can i make json object from

{
    "Public_Holiday": [{
          "id": 1,
          "date": "2018-12-31T15:59:14.000Z"
    }]
}

Into this and add momentjs

{
    "Public_Holiday": [{
          "id": 1,
          "date": "2019-1-1"
    }]
}

And i tried to restructure json by doing

const items = await jsonfile.readFile('./json/data.json');
const objKey = Object.keys(items);
const json_struct = objKey.map((key) => {
    tablename: key,
    table: items[key]
})

So how can i filtered the json_struct with every object date and increment it by 1?

myrul
  • 33
  • 5
  • Depend on your preference, you can use moment js library for format the date, or it could be regular expression to split the things out if that just a string. – kamprasad Nov 07 '19 at 03:53
  • What is the algorithm to convert "2018-12-31T15:59:14.000Z" to "2019-1-1"? – RobG Nov 07 '19 at 04:04
  • actually im using convert-excel-to-json library that use another library called sheetjs to parse excel document into json. the output will appear like code above but the library itself have a problem in parsing date from excel. Then im using another alerternative by using momenjs to add 1 day from the ISO based timestamp – myrul Nov 07 '19 at 04:09
  • 1
    Possible duplicate of [Incrementing a date in JavaScript](https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript) – Sheepy Nov 07 '19 at 04:16

0 Answers0