Is Document Generation API fully compliant with JSONata?

Community Beginner ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

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.

TOPICS
Document Generation API

Views

277

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Apr 28, 2022 Apr 28, 2022

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

...

Likes

Translate

Translate
Community Beginner ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 18, 2022 Mar 18, 2022

Copy link to clipboard

Copied

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/#li...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 18, 2022 Mar 18, 2022

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 19, 2022 Mar 19, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

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 ()  .

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

Had trouble posting into the above, so trying here again

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 22, 2022 Mar 22, 2022

Copy link to clipboard

Copied

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. 🙂 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 22, 2022 Mar 22, 2022

Copy link to clipboard

Copied

Makes perfect sense.  I am just climbing out of the noob phase w.r.t. the philosophy on how to balance between the two.  Thanks again for your terrific advice and an outstanding suite of products and support.

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

I am back as I have a fundamental misunderstanding of 'repeating sections' which I thought I got with the advice above.

 

Below is the array I pass to the variable "foo" to be accessed in the doc.  I have other non-nested json I pass to other variables which is accessible in the doc without issue.


{
"_type": "SpellCheck",
"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"
}
]
}
---

 

I don't get any result however. Should it be accessible in the doc as-is or should I subset it and/or flatten it with node.js or jsonata in node.js first?

 

{% conditional-section expr( test2 != ‘NoErrors’) %}
{% repeating-section test2.flaggedTokens %}
{{ token }} –
{{ suggestions.suggestion}} –
{{ suggestions.score}}
{% end-section %}
{% end-section %}

---

What I am trying to do as a final result is create a list of subsections with token, suggestions.score, suggestions.suggestion for each token. Thanks in advance

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

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:

RaymondCamden_0-1651154387914.png

And got this result:

 

RaymondCamden_1-1651154409016.png

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 01, 2022 May 01, 2022

Copy link to clipboard

Copied

LATEST

Thank you! This worked very well.

 

If anyone else comes across this and is using AWS Step Functions + node.js, consider this extra step. If you pass an entire upstream payload from a database and are failing to access the inner nodes of your json object, break out the troublesome section into a separate parameter variable.  I am unsure why AWS seems to mask access, or I am missing something, and am approaching them with the issue.

 

Don't do this:

"Parameters": {
"Payload.$": "$",
}

 

Do this:

"Parameters": {
"Payload.$": "$",
"troublesome-object.$": "$.troublesome-object"
}

It repeats the troublesome-object data (since its also in the larger Payload) but you are able to pass it to the document generation api and access everything within.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

Thank you for the fast response. Much appreciated. I had a fleeting thought about trying a second repeat-section within the first one but was trying to get the higher level, 'token' rendering first.  Will review your code below in the next few days.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources