Search for a charactter in a file

this file will be passed to an java sript evry time that there is some web request,when i recieve the request i need write in the end of the file ' ]' to close the function,
but once the web request finish ,i need to cancel the ']',and write th temperture

In that scenario, I would never write the ] to the file, but include it in the output to the java script.