API Help

Grant Edwards grant.b.edwards at gmail.com
Wed Jun 14 19:40:58 EDT 2017


On 2017-06-14, justin walters <walters.justin01 at 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










More information about the Python-list mailing list