Skip to main content
GuillaumeCleme13307245
Participant
April 27, 2022
Question

Injecting object index in Document Generation API {% repeating-section %} tag

  • April 27, 2022
  • 1 reply
  • 346 views

Hi folks,

 

I'm trying something slightly advanced with the Document Generation API JSONata syntax by trying to inject an object's index into the object itself. 

 

I've reviewed the JSONata processing model and understand that it's possible to get an object's position in the array using the `#$var` syntax as described here: https://docs.jsonata.org/processing. The JSONata documentation also shows an example of this syntax here: https://docs.jsonata.org/path-operators#-positional-variable-binding 

 

Given the following JSON:

{
    "winners": [
        {
            "firstName": "Bob",
            "lastName": "Ross"
        },
        {
            "firstName": "John",
            "lastName": "Doe"
        }
    ]
}

I would like to use a Document Generation tag like the following:

{% repeating-section winners#$i.{'firstName': firstName, 'lastName': lastName, 'position': $i} %}
•	Race participant {{firstName}} {{lastName}} completed the race in position: {{position}}
{% end-section %}

I've tried just about every combination of the syntax both in the repeatable content tags and in the `repeating-section` tag but I cannot get the array position to be injected. The `repeating-section` tag is simply omitted from the resulting document. Something interesting to note is that object property reassignment works perfectly well:

{% repeating-section winners.{'f': firstName, 'l': lastName} %}
•	Race participant {{f}} {{l}} completed the race
{% end-section %}

Has anyone successfully done this or is support for this syntax limited?

 

Cheers,

This topic has been closed for replies.

1 reply

Raymond Camden
Community Manager
Community Manager
April 27, 2022

As far as I know it's not possible, but don't forget you can manipulate your array data before sending it to the API. In winners, for each object, you can assign an index/idx/etc value yourself.