From: Jeff Hostetler Date: Mon, 11 Jun 2018 11:51:13 GMT Subject: Re: [PATCH v8 1/2] json_writer: new routines to create data in JSON format Message-ID: In-Reply-To: <0690b5a8-6c1c-e664-bb89-5d4e48258ddb@web.de> On 6/8/2018 4:07 PM, René Scharfe wrote: > Am 07.06.2018 um 16:12 schrieb git@jeffhostetler.com: >> From: Jeff Hostetler [...] >> + if (jw->first_stack.buf[jw->first_stack.len - 1] == '1') >> + jw->first_stack.buf[jw->first_stack.len - 1] = '0'; >> + else >> + strbuf_addch(&jw->json, ','); > > You only need a binary flag to indicate if a comma is needed, not a > stack. We need a comma at the current level if and only if we already > wrote a child item. If we finish a level then we do need a comma at the > previous level because we just wrote a sub-object or sub-array there. > And that should cover all cases. Am I missing something? > > I get a sense of déjà vu, by the way. :) [...] Yes, your way is simpler. I'll update and re-roll. (And yes, we did discuss this earlier. I found a problem with my first version where it wouldn't handle empty sub-items, but you found the missing piece.) Thanks Jeff