I have created a library exactly for this purpose:
It's called Docxgen and can be found on github: https://github.com/edi9999/docxgenjs
Here's a usage example of how to use it:
Used content: Hello {first_name} {last_name}
var doc= new DocxGen(docData); //Create a new DocxGen document
doc.setTemplateVars(
{"first_name":"Hipp",
"last_name":"Edgar",
}
) //set the templateVariables
doc.applyTemplateVars() //apply them (replace all occurences of {first_name} by Hipp, ...)
doc.output() //Output the document using Data-URI
Here's the example live on my site: http://javascript-ninja.fr/docxgenjs/examples/demo.html
Okay this is javascript, but:
it runs on node when you install it globally, as a command line:
docxgen <inputFileDocx> <inputFileJson>
More about the installation on the github repo: https://github.com/edi9999/docxgenjs#node-installation-and-usage
Hope this helps