A while back I built the first version of ndocx – a utility that you can call in your terminal to populate standard Word templates. It can used to generate documents based on simple JSON files. You can think of it as a Word document visualizer of your JSON files. The ndocx utility doesn’t need Word or any other application to be installed on the machine, which makes it a good fit for services and you don’t need any license to run it. It’s real open source alternative that you can use as you wish.
ndocx is in fact the command line interface of Novo Docx, a library based on the latest .NET Framework. You can also find an Azure Functions App that exposes the same functionality as a REST service. This is a good alternative if you don’t want to deal with document manipulation yourself.
If you have a JSON file and a word template, using ndocx is as easy as the following command.
ndocx populate mytemplate.docx -params params.json -output output.docx
Take the following word template as an example.

It has just one placeholder called a
. In order to populate that place holder, you would need a JSON file like the following.
{
"a": "simple test"
}
In other words for each placeholder in your word template, you would need an attribute in your JSON file with the exact same name.
If you have repeating section in your word template, you will need an array for your repeating section and inside the array each placeholder (that you want to populate) needs a matching attribute. For example the following JSON, has a simple attribute called “a” and an array called “repeating1”.
{
"a": "simpla test",
"repeat1": [
{"a": "Col 1 - row 1", "b": "col 2 - row 1"},
{"a": "Col 1 - row 2", "b": "col 2 - row 2"}]
}
The given JSON file can match the following word document, with a simple placeholder called “a” and a repeating section called “repeat1”.

Just keep in mind that currently only “Plain text content control” and “Repeating section content control” are supported which should be enough for majority of use cases.
You can download the latest release of ndocx from its Github repository, Novo Docx.
Leave a Reply