[Cialug] What's a JSON Document?
David W. Body
davidbody at bigcreek.com
Thu Aug 30 22:02:05 UTC 2018
A practical way to find out what is and isn't valid JSON is to use
JavaScript's JSON.parse() and JSON.stringify() functions. You can do this
in a node repl or in your browser's console.
For example,
> var p = JSON.parse("{}")
undefined
> p
{}
> var p = JSON.parse("{} {}")
SyntaxError: Unexpected token { in JSON at position 3
> JSON.stringify("hello world")
'"hello world"'
> var p = JSON.parse('"hello world"')
undefined
> p
'hello world'
--David
On Thu, Aug 30, 2018 at 1:25 PM, Dave Hala <dave at 58ghz.net> wrote:
> I wonder if being loosely defined is actually problematic in practice? Has
> anyone ever ran into a situation where exchanging data via json didn't
> work?
>
> :) Dave
>
> On Thu, Aug 30, 2018 at 1:08 PM Scott Yates <Scott at yatesframe.com> wrote:
>
> > Since JSON often gets de-serialized, i tend to think of it as conforming
> to
> > a JavaScript "object". Meaning "one object with many properties, or
> nested
> > objects/arrays"
> >
> > The problem (or advantage maybe) is that JSON is extremely loosely
> defined
> > (as you have noticed).
> >
> > On Thu, Aug 30, 2018 at 11:06 AM Todd Walton <tdwalton at gmail.com> wrote:
> >
> > > I know what JSON is. But I don't know what a JSON document is defined
> as.
> > > Wait, scratch that. It's not called a "document", it's called a "text".
> > >
> > > So I went off researching JSON this morning, and here are some things I
> > > found:
> > >
> > > 1) ECMA defines it, of course, being it's derived from
> > > JavaScript/ECMAScript. There's also an RFC: 8259.
> > > 1a) RFC 8259 was published just last December!
> > > 2)
> > >
> > https://www.ecma-international.org/publications/files/ECMA-
> ST/ECMA-404.pdf
> > > 3) https://tools.ietf.org/html/rfc8259
> > > 4) ECMA says "JSON" is pronounced like "Jason". I prefer to say
> > "jay-sawn".
> > > 5) ECMA is a *lot* sloppier with their specifications than the IETF,
> and
> > > with the quality of their documentation.
> > > 5a) <rant> ECMA! Shill for Microsoft. Skin disease. So on. </rant>
> > > 6) "Hello, world" is a complete JSON text. Nothing says you have to
> have
> > > braces or brackets.
> > > 7) Unicode is not actually strictly required.... (I did not expect
> that.)
> > >
> > > So my question... Must a JSON text be *one* object or *one* array or
> > *one*
> > > unstructured string, number, or allowed constant? And must objects and
> > > arrays be separated by a comma? Is the text between these dashed lines
> a
> > > conforming JSON text?:
> > >
> > > ------------
> > > { "name": "Todd", "occupation": "scalawag" }
> > > { "fruit": "orange", "delicious": true }
> > > ------------
> > >
> > > --
> > > Todd
> > > _______________________________________________
> > > Cialug mailing list
> > > Cialug at cialug.org
> > > http://cialug.org/mailman/listinfo/cialug
> > >
> > _______________________________________________
> > Cialug mailing list
> > Cialug at cialug.org
> > http://cialug.org/mailman/listinfo/cialug
> >
>
>
> --
> NIFCAP -The Premier Client Intake System for Non-Profit Organizations.
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>
More information about the Cialug
mailing list