Skip to main content
Known Participant
March 15, 2022
Answered

Is Document Generation API fully compliant with JSONata?

  • March 15, 2022
  • 2 replies
  • 4017 views

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 has been closed for replies.
Correct answer Raymond Camden

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:

 

 

 

2 replies

Raymond Camden
Community Manager
Community Manager
March 18, 2022

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?

Vince5E52Author
Known Participant
March 20, 2022

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'
}
], 

Raymond Camden
Community Manager
Community Manager
March 21, 2022

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?

Vince5E52Author
Known Participant
March 15, 2022

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

Raymond Camden
Community Manager
Community Manager
March 18, 2022

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