On Wed, Jun 14, 2017 at 4:40 PM, Grant Edwards <grant.b.edwa...@gmail.com> wrote:
> On 2017-06-14, justin walters <walters.justi...@gmail.com> wrote: > > > I should also specify that the data you have received is malformed. > > > > JSON should always have an object as the top level structure, not an > > array as in your data. > > Where is that requirement stated? > > RFC7159 explicitly states that a "conforming JSON text" can be either > an array or an object: > > > 2. JSON Grammar > > A JSON text is a sequence of tokens. The set of tokens includes > six structural characters, strings, numbers, and three literal > names. > > A JSON text is a serialized value. Note that certain previous > specifications of JSON constrained a JSON text to be an object or > an array. Implementations that generate only objects or arrays > where a JSON text is called for will be interoperable in the sense > that all implementations will accept these as conforming JSON > texts. > > The grammar specified by later in that section also allow a JSON text > to contain nothing but a single simple value: string, number 'null' > 'true' or 'false'. IOW, a file containing a single digit (0-9) is > valid JSON. > > -- > Grant > > > > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > That's why I said "should", not "required". Generally, it's considered best practice for web APIs. I also did not say that the data is "invalid", I said it is "malformed". -- https://mail.python.org/mailman/listinfo/python-list