Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request : Final comma #47

Open
benel opened this issue Oct 2, 2024 · 0 comments
Open

Feature request : Final comma #47

benel opened this issue Oct 2, 2024 · 0 comments

Comments

@benel
Copy link

benel commented Oct 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant