Subject: Re: [PATCH iproute2 net-next v3 1/5] json_writer: allow base json data type to be array or object

From: Stephen Hemminger <[email-masked]>
Date: Tue, 21 Jun 2016 09:52:44 -0700

On Tue, 21 Jun 2016 09:24:50 -0700
Anuradha Karuppiah <[email-masked]> wrote:

> On Tue, Jun 21, 2016 at 9:12 AM, Stephen Hemminger
> <[email-masked]> wrote:
> > On Mon, 20 Jun 2016 23:39:43 -0700
> > Roopa Prabhu <[email-masked]> wrote:
> >
> >> From: Anuradha Karuppiah <[email-masked]>
> >>
> >> This patch adds a type qualifier to json_writer. Type can be a
> >> json object or array. This can be extended to other types like
> >> json-string, json-number etc in the future.
> >>
> >> Signed-off-by: Anuradha Karuppiah <[email-masked]>
> >
> > Since json writer is not used in many places yet, why not just
> > get rid of the automatic object in the constructor.
> 
> I wanted to force the external api to start with an json-object or
> json-array. It reduces the chance of mistakes vs. a typeless
> constructor. With a typeless constructor you can accidentally end up
> with a json output that doesn't pass json lint; especially if optional
> params are being suppressed at different places.

Still, this is not how jsonwriter works in .NET, Android, or Java.
It is easily confusing to developers if similar API's behave
differently.  Kind of like if printf() always appended a new line
on some platforms.