I have a text file that is being generated by the Apache Flink Tool. 1. My goal is to extract the contents of this file until it reaches the 999th "}," occurrence. 2. After extraction, remove the last comma(,) from the content. 3. Add "[" at the beginning and "]" at the end of the extracted content. 4. Save this modified content into a variable.
All of these steps need to be executed within a variable.
Is it feasible to perform this entire operation using Javascript?
The intention behind this task is to format the data as a JSON array suitable for plotting Highcharts, which can handle up to 1000 points at once.
Here are the initial contents of the txt file written by Flink:
{"temperSensorData":"28.489084691371996","temperSensorUnit":"celsius","timestamp":"1493270171424","timestamp2":"1493270171454","timestamp3":"1493270171454"},
{"temperSensorData":"28.48908469137112","temperSensorUnit":"celsius","timestamp":"1493270171426","timestamp2":"1493270171522","timestamp3":"1493270171523"},
{"temperSensorData":"28.489084691371186","temperSensorUnit":"celsius","timestamp":"1493270171426","timestamp2":"1493270171523","timestamp3":"1493270171524"},
{"temperSensorData":"28.489084691371595","temperSensorUnit":"celsius","timestamp":"1493270171426","timestamp2":"1493270171524","timestamp3":"1493270171525"},
{"temperSensorData":"28.48908469137168","temperSensorUnit":"celsius","timestamp":"1493270171428","timestamp2":"1493270171529","timestamp3":"1493270171529"},
{"temperSensorData":"28.489084691371684","temperSensorUnit":"celsius","timestamp":"1493270171428","timestamp2":"1493270171529","timestamp3":"1493270171529"},
This is the desired (JSON) format after applying all the aforementioned actions:
[
{
"temperSensorData": "28.489084691371996",
"temperSensorUnit": "celsius",
"timestamp": "1493270171424",
"timestamp2": "1493270171454",
"timestamp3": "1493270171454"
},
{
"temperSensorData": "28.48908469137112",
"temperSensorUnit": "celsius",
"timestamp": "1493270171426",
"timestamp2": "1493270171522",
"timestamp3": "1493270171523"
},
{
"temperSensorData": "28.489084691371186",
"temperSensorUnit": "celsius",
"timestamp": "1493270171426",
"timestamp2": "1493270171523",
"timestamp3": "1493270171524"
}
]