Saturday, 10 June 2017

Read, Transform, Write JSON file using Node.js

I have a JSON file like so:

{
   key1: "value1",
   key2: "value2",
   key3: {
     key3_1: "value3_1",
     key3_2: "value3_2"
   }
}

I would like to use Node.js to read the JSON file, transform the values for keys where appropriate and write the resulting JSON in a file once the transformation is done. The challenge here is that the transformation of value typically takes a few milliseconds (it is a web request/response flow).

I am unable to think about the correct way of doing it due to the asynchronous nature of Node.js.

Any pointers are highly appreciated.



via Rahul Soni

No comments:

Post a Comment