Let us consider a practical scenario
Assume you have some data where everything is string and it represents as below:
You have to format and return the data as below:
Basically, after getting the data you have to change Data-types and return the required JSON.
Note:
- Have a look at JSON data before writing the code
- All the code should be written in "tindex.js" file
- Select Run -> install to install the dependencies.
- Select Run -> Run server to validate JSON schema.
- Select Run -> Test Test to validate your JSON data.
Answer:
module.exports= function(){
const data = require("./testdata.json");
/*Explore the JSON file and return required JSON data*/
var json = JSON.parse(data).studentData;
json.forEach(function(element, index){
element['aggregate'] = parseInt(element['aggregate']);
element.forEach(function(per,ind){
per['sub1'] = parseInt(per['sub1']);
per['sub2'] = parseInt(per['sub2']);
per['sub3'] = parseInt(per['sub3']);
});
});
return json;
}
Screenshot for reference:
No comments:
Post a Comment
If you have any doubts, Please let us know.