Use Mustache to iterate a root list

I have a long JSON response and I want to use a mustache template to parse it. I’ve been using http://mustache.github.io/#demo to verify my template. While it works at the demo site it does not work in the webhook response template. My template and JSON sample are below:

{{#.}}
    {{ReservationType}}|
{{/.}}

A sample of the JSON:

[
  {
    "BillingInstallment": "SinglePayment", 
    "Description": "Basic Operation Woodshop", 
    "IsAutoPay": false, 
    "IsComped": false, 
    "IsIndividual": true, 
    "IsRecurring": false, 
    "IsUnlimited": false, 
    "NumberOfSessions": 1, 
    "PackageID": 15838970, 
    "PackageLengthQuantity": 0, 
    "PackageLengthTimeUnit": "Undefined", 
    "PackagePlanID": 195011, 
    "RecurrencePatternOccurrences": 0, 
    "RecurrencePatternQuantity": 0, 
    "RecurrencePatternUnit": "None", 
    "RenewAsPackagePlanID": 0, 
    "ReservationType": "Class Woodshop BOSS", 
    "ReservationTypeID": 190474
  }, 
  {
    "BillingInstallment": "None", 
    "Description": "Vinyl Cutter / Heat Press certified member", 
    "EndDate": "2019-11-20T00:00:00", 
    "IsAutoPay": false, 
    "IsComped": false, 
    "IsIndividual": false, 
    "IsRecurring": true, 
    "IsUnlimited": false, 
    "NumberOfSessions": 3, 
    "PackageID": 15838971, 
    "PackageLengthQuantity": 0, 
    "PackageLengthTimeUnit": "Undefined", 
    "PackagePlanID": 202351, 
    "RecurrencePatternOccurrences": 1, 
    "RecurrencePatternQuantity": 1, 
    "RecurrencePatternUnit": "Weekly", 
    "RenewAsPackagePlanID": 202351, 
    "RenewalDate": "2019-11-13T00:00:00", 
    "ReservationType": "EQ: Vinyl Cutter / Heat Press", 
    "ReservationTypeID": 198567, 
    "StartDate": "2019-11-14T00:00:00"
  }
]

I hope to get

Class Woodshop BOSS|EQ: Vinyl Cutter / Heat Press|

If I reference a single element it works to get a single value, but not the . to iterate the list. This works

{{#0}}
    {{ReservationType}}|
{{/0}}

to return

Class Woodshop BOSS|

Any hints are appreciated.
Jim

Hello?

Have you considered using JSONParserGeneratorRK which I know works or JSONSTREAMINGPARSER library?

@JSchrempp, first, I encourage you to use @rickkas7’s Mustache tester found here:

http://rickkas7.github.io/mustache/

When I run your first template:

{{#.}}
    {{ReservationType}}|
{{/.}}

I get the response you expected

    Class Woodshop BOSS|
    EQ: Vinyl Cutter / Heat Press|

When I test with the second template:

{{#0}}
    {{ReservationType}}|
{{/0}}

I get the first element as expected. Perhaps the Cloud Mustache parser is not behaving as expected. @rickkas7, any thoughts?

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.