Generate Word Documents from Template using JSON Data (in Java)

@Team,

Please help me in in the followings:
I have a Word Template (template.docx), and a json file (nestedJSONData.json) which I’d like to use for creating a Word document (property_rental_contract.docx), and using the data of the json file to populate my template.

My source code is written in JAVA.

When I’m trying to access data from the nested JSON, I got the following error message:
“Exception in thread “main” java.lang.IllegalStateException: An error has been encountered at the end of expression ‘data.landlord.n’. Can not get the value of member ‘landlord’ on type ‘class com.aspose.words.net.System.Data.DataRow’.”

Here is the details of the project:

JSON (nestedJSONData.json):

{
  "landlord":
  {
    "name": "Louise Landlord",
    "birthPlace": "Budapest",
    "birthDate": "1978-12-01"
  },
  "tenant":
  {
    "name": "Thomas Tenant",
    "birthPlace": "Budapest",
    "birthDate": "1980-01-01"
  }
}

Template (template.docx):

//………..
name: 				<<[data.landlord.name]>>
place and date of birth:	<<[data.landlord.birthPlace]>>, <<[data.landlord.birthDate]>>
as Landlord,

name: 				<<[data.tenant.name]>>
place and date of birth:	<<[data.tenant.birthPlace]>>, <<[data.tenant.birthDate]>>
as Tenant,
//…………..

JAVA (source code):

Document doc = new Document("template.docx");
JsonDataSource dataSource = new JsonDataSource("nestedJSONData.json");
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, dataSource, "data");
doc.save("property_rental_contract.docx");

NOTES:
(1) I think that to working with foreach would not be a good idea in my case, becase I want to access specific items (persons) from my JSON.
(2) Unfortunately I got stuck at the very beginning of my project (based on the above error msg), but the plan is that if I found the way to access the specific object in my JSON, I’ll put many other information into my JSON (like e.g.: data of the property, rental cost, starter and end date of the contract etc).

I’m trusting you to send me a quick answer which is solve my problem and I can continoue on my project.

Thanks for your support in advance,

Krisztián Kovács

@KriszProg

We have logged this problem in our issue tracking system as WORDSNET-21606. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@Tahir,

Thanks for your quick reply.
My problem is very similar to the case: WORDSNET-21443 (although that problem arise in c # not in Java). As I see you have managed to resolve that problem (21443) and the solution will coming soon in the 21.1 release.

Since my problem is very similar (only the language is different) the question arises: is it possible that 21.1 release will contain the solution for Java as well?

It would be really great!

@KriszProg

Yes, the same issue will be fixed in the next version of Aspose.Words for Java i.e. 21.1. We will inform you via this forum thread once new version of Aspose.Words for Java is available for fix WORDSNET-21443. We will check if this issue is duplicate of WORDSNET-21606.

The issues you have found earlier (filed as WORDSNET-21443) have been fixed in this Aspose.Words for .NET 21.1 update and this Aspose.Words for Java 21.1 update.

The issues you have found earlier (filed as WORDSNET-21606) have been fixed in this Aspose.Words for .NET 21.2 update and this Aspose.Words for Java 21.2 update.

A post was split to a new topic: Can not get the value of member upon building reort