Skip to main content
Known Participant
March 15, 2022
Answered

Is Document Generation API fully compliant with JSONata?

  • March 15, 2022
  • 2 replies
  • 4033 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 22, 2022

I am unsure if the MS doc will help since after I posted the above, I was able to flatten the array and pass it.  I haven't tested it so perhaps doing it in the doc is the better way.  The screenshot below is what I am trying to get to.  Essentially one token (key) and 1 or more arrays which include the variables seen in column #2 and column #3 ()  .

 

 


So one thing I'd say is - there is a philosophy of how much logic should be in the template versus your sample data. You can't do *everything* in the template so in cases where that fails, it's absolutely ok to do it in your data. In general, even if the template supported _any_ logic, I'd still consider doing some stuff in data vs the template, just to keep things simpler there. Does that make sense? It sounds like you have things working and if so - cool. 🙂 

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