@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