Free Support Forum - aspose.com

Generate Word Documents (Reports) from Templates using JSON Data Source in C# .NET | LINQ Reporting Engine | DataRow

I have a problem when json contains several different objects on top level.
I know that if a top-level JSON element represents an object, a JsonDataSource instance should be treated in template documents in the same way as if it was a DataRow instance,
but in this case I can use in template only properties from first object in Json.

I am trying to use a json that looks like this:

{
"FirstPart": {
	"FirstTag": "FirstValue",
	"SecondTag": "SecondValue"
},
"SecondPart": {
	"FirstUsername": "User",
	"SecondAge": 5
}
}

my template.docx :

FirstPart.FirstTag: <<[ds.”FirstTag”]>>
FirstPart.SecondTag: <<[ds.”SecondTag”]>>
SecondPart.FirstUsername: <<[ds.”FirstUsername”]>>
SecondPart.SecondAge: <<[ds.”SecondAge”]>>

and results looks like this:

FirstPart.FirstTag: FirstValue
FirstPart.SecondTag: SecondValue
SecondPart.FirstUsername: 
SecondPart.SecondAge: 

but i am expecting the following result

FirstPart.FirstTag: FirstValue
FirstPart.SecondTag: SecondValue
SecondPart.FirstUsername: User
SecondPart.SecondAge: 5

If the template contained a simple field at the top level, then I would be able to correctly access all properties using the name of the parent object:

{
"FirstPart": {
	"FirstTag": "FirstValue",
	"SecondTag": "SecondValue"
},
"SecondPart": {
	"FirstUsername": "User",
	"SecondAge": 5
},
"ThirdData": 11
}

with template

FirstPart.FirstTag: <<[ds."FirstPart".”FirstTag”]>>
FirstPart.SecondTag: <<[ds."FirstPart".”SecondTag”]>>
SecondPart.FirstUsername: <<[ds."SecondPart".”FirstUsername”]>>
SecondPart.SecondAge: <<[ds."SecondPart".”SecondAge”]>>

returns the result as expected:

FirstPart.FirstTag: FirstValue
FirstPart.SecondTag: SecondValue
SecondPart.FirstUsername: User
SecondPart.SecondAge: 5

How in the first case can I access the fields of the second object? What am I missing?

In the attachment simple .Net Core console app with this case and input Json, input template docx, output result docx and expected docx.

AsposeTest.zip (197.5 KB)

@asposeuuups,

We have managed to reproduce this problem on our end and logged it in our issue tracking system with ID WORDSNET-21443. We will further look into the details of this problem and will keep you updated on the status of linked ticket. We apologize for your inconvenience.

1 Like