webroo / dummy-json

Generates random dummy JSON data in Node.js
MIT License
380 stars 61 forks source link

Feature request : Final comma #47

Open benel opened 1 week ago

benel commented 1 week ago

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 :

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.