Skip to content

Feature request : Final comma #47

@benel

Description

@benel

Let's say we designed the following pattern:

{
  {{#repeat min=0 max=1}}
  "creator": "{{firstName}} {{lastName}}",
  {{/repeat}}
  "parts": [
    {{#repeat min=3 max=15}}
      {"paragraph" : {{lorem min=5 max=120}}},
    {{/repeat}}
    {{#repeat min=3 max=15}}
      {"comment" : {{lorem min=5 max=120}}},
    {{/repeat}}
  ]
}

While completely understandable, it may generate invalid JSON :

  • if a creator is generated, there will be a missing comma after it,
  • there will be always a missing comma between the last paragraph and the first comment.

Please note that adding a comma in the pattern could be a solution for the second case but not for the first one, because with 0 occurrences there would be an unexpected comma.

Such a following pattern could work if there was an additional boolean parameter of the repeat clause, named last_comma (or any other name) which would default to false (for compatibility with current behaviour) but could be set to true in the first two repeats.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions