Skip to main content
Known Participant
Mar 15, 2022 5:33 AM UTC
Answered

Is Document Generation API fully compliant with JSONata?

I am able to do something with the JSONata 'try' editor which gets nothing rendered when I move the same code to MS Word.

 

For example, this query--> $.foo.suggestions.suggestion results in the array I need, "["Hello","Hollow","world"]".  I alos noted that "foo.suggestions.suggestion" without the prefix notation works.

 

But when I add to MS Word using a repeating set like so, no results.

 

{% repeating-section foo %}

• {{ suggestions.suggestion }}

{% end-section %}

 

Welcome any insights.

This topic is closed to new replies. Start a new post to keep the conversation going.
Raymond Camden
Raymond CamdenCorrect answer
Community Manager
Apr 28, 2022 2:00 PM UTC

If I read this right, flaggedTokens is an array of arrays. I see your repeating over it above, but I do not see you repeating over the sections inside - have you tried that?


It's working for me. Here was my source JSON:

{
	"flaggedTokens": [
		{
			"suggestions": [
				{
					"score": 0.9156124677361996,
					"suggestion": "Hello"
				},
				{
					"score": 0.7855285220164744,
					"suggestion": "Hollow"
				}
			],
			"offset": 0,
			"type": "UnknownToken",
			"token": "Hollo"
		},
		{
			"suggestions": [
				{
					"score": 0.9156124677361996,
					"suggestion": "world"
				}
			],
			"offset": 7,
			"type": "UnknownToken",
			"token": "wrld"
		}
	]
}

 And then I used this in Word:

And got this result:

 

 

 

14 replies

Raymond Camden
Community Manager
Community Manager
Mar 18, 2022 2:35 PM UTC

So first - note that while Document Generation uses JSONata, it is not 100% compliant. Can you tell me how foo is defined? Maybe share your JSON?

Translate
Vince5E52Author
Known Participant
Mar 20, 2022 1:36 AM UTC

Thank you for the offer.  The issue is one token can be linked with numerous suggestions and so when I try to put it into a table, I get separate subsections. Would appreciate knowing if this can be done as I have been looking at flattening everything but am not super facile with node.js. Mea culpa on the formatting!

 

foo: [
{
suggestions: [Array],
offset: 0,
type: 'UnknownToken',
token: 'Hollo'
},
{
suggestions: [Array],
offset: 7,
type: 'UnknownToken',
token: 'wrld'
}
], 

Translate
Raymond Camden
Community Manager
Community Manager
Mar 21, 2022 12:48 PM UTC

I need a bit more help. Can you explain how you want the result to look? Perhaps you could mock up a quick Word doc and attach it here?

Translate
Vince5E52Author
Known Participant
Mar 15, 2022 6:47 AM UTC

Similarly using "$." notation in the tags doesn't seem to do anything/

Translate
Raymond Camden
Community Manager
Community Manager
Mar 18, 2022 2:38 PM UTC

If you have an array of simple values and want to display them in a loop, you use $[0]. This is documented at the end of this section: https://developer.adobe.com/document-services/docs/overview/document-generation-api/templatetags/#lists

Translate