JSON Pointer

32 views
Skip to first unread message

Paul C. Bryan

unread,
Jun 8, 2011, 4:26:10 PM6/8/11
to json-...@googlegroups.com
I have a first draft of JSON Pointer ready, under some preliminary review before I publish a Internet-Draft.

I am looking at "$ref" now with some thoughts:

1. I think "$ref" value should always be a URI.
2. It should be able to reference an arbitrary node within another JSON document using the fragment identifier (e.g. "http://somehost/somedoc.json#/foo/bar").
3. It should reference a property within the containing document by using only fragment identifier (e.g. "#/foo/bar").

Thoughts?

Paul

Jack Vinijtrongjit

unread,
Jun 8, 2011, 4:54:01 PM6/8/11
to json-...@googlegroups.com
100% agreed.

I gave the exact same suggestion to Dean Landolt for Draft 4. Without being able to reference arbitrary node within another JSON document, it's actually not useable when you have so many common schemas since you end up with 100+ schemas for a simple project. Referencing arbitrary node will allow developers to group related schema together in the same schema file, which also make it much easier to discover and share.

For example: Contact schema may contain Address, Phone, Email, etc and that any of these contained schemas can be used else where without having to reference the root schema (Contact). I have also suggested to make certain contained schema private or public. When it's private, it cannot be directly referenced. It's simply there as part of another schema.

What we need is basically what was achieved by XSD for XML. Why reinvent the wheel if it was already done once in a different protocol? Some people may argue that the reason all schemas are in its own file is to reduce the size of components that must be loaded into the browser, but I don't think that matters so much any more.

Thanks,
Jack



--
You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To post to this group, send email to json-...@googlegroups.com.
To unsubscribe from this group, send email to json-schema...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-schema?hl=en.

Nate Morse

unread,
Jun 8, 2011, 4:56:07 PM6/8/11
to json-...@googlegroups.com
wondering... Could integers be included in the path to point into an array?
e.g. if  bar was an array "#/foo/bar/0" would point to the first element
or if foo was an array, then "#/foo/1/bar" would point to foo[1].bar.

thanks,
--Nate

--

Paul C. Bryan

unread,
Jun 8, 2011, 5:00:29 PM6/8/11
to json-...@googlegroups.com
On Wed, 2011-06-08 at 16:56 -0400, Nate Morse wrote:
wondering... Could integers be included in the path to point into an array?

Yes, definitely.


e.g. if  bar was an array "#/foo/bar/0" would point to the first element
or if foo was an array, then "#/foo/1/bar" would point to foo[1].bar.

Yes, both are exactly how JSON Pointer specifies how to interpret these.

Paul

Daniel Kec

unread,
Jun 9, 2011, 8:43:05 AM6/9/11
to json-...@googlegroups.com
There is a serious problem with: "#/foo/bar/0",
if bar have descendant object with name "0": somevalue. or worse what
if foo have descendant object with name "bar/0" and descendant array
with name bar? We cant use just some clone of xpath because:
"A string begins and ends with
quotation marks. All Unicode characters may be placed within the
quotation marks except for the characters that must be escaped:
quotation mark, reverse solidus, and the control characters (U+0000
through U+001F)." from JSON spec - http://www.ietf.org/rfc/rfc4627.txt

I mean there is no way to query JSON without quotation marks and
escaping of unwanted characters.Then it would look like:
#/"foo"/"bar"/0
and that is ugly.

Daniel


2011/6/8 Paul C. Bryan <paul....@forgerock.com>:

> --
> You received this message because you are subscribed to the Google Groups
> "JSON Schema" group.
> To post to this group, send email to json-...@googlegroups.com.
> To unsubscribe from this group, send email to
> json-schema...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/json-schema?hl=en.
>

--
Daniel Kec

Nate Morse

unread,
Jun 9, 2011, 9:47:23 AM6/9/11
to json-...@googlegroups.com
If bar is an array, then "#/foo/bar/0" should be able to reference into it.
On the other hand, if bar is an object then it would reference the property "0".
If you want to reference an property that is named "bar/0", it might be done with "#/foo/bar\/0", or some other escape scheme.
--Nate

Paul C. Bryan

unread,
Jun 9, 2011, 10:30:16 AM6/9/11
to json-...@googlegroups.com
On Thu, 2011-06-09 at 14:43 +0200, Daniel Kec wrote:
There is a serious problem with: "#/foo/bar/0",
 if bar have descendant object with name "0": somevalue. or worse what
if foo have descendant object with name "bar/0" and descendant array
with name bar? We cant use just some clone of xpath because:
"A string begins and ends with
   quotation marks.  All Unicode characters may be placed within the
   quotation marks except for the characters that must be escaped:
   quotation mark, reverse solidus, and the control characters (U+0000
   through U+001F)." from JSON spec - http://www.ietf.org/rfc/rfc4627.txt

I mean there is no way to query JSON without quotation marks and
escaping of unwanted characters.Then it would look like:
#/"foo"/"bar"/0
and that is ugly.

The property reference token sequence is: foo, bar, 0. The last value is interpreted as either a property name or an array offset, depending on the node in the target object being evaluated. An excerpt from the JSON Pointer draft:

“If the current target node is a JSON object, then the new target is the value of the property with the name identified by the next property reference token. If the current target node is a JSON array, then the new target is the value of the item in the array with the zero-based index identified by the next property reference token (which MUST be a non-negative integer number value).”

Paul

Kris Zyp

unread,
Jun 9, 2011, 11:14:51 AM6/9/11
to json-...@googlegroups.com, Daniel Kec
On 6/9/2011 6:43 AM, Daniel Kec wrote:
> There is a serious problem with: "#/foo/bar/0",
> if bar have descendant object with name "0": somevalue. or worse what
> if foo have descendant object with name "bar/0" and descendant array
> with name bar? We cant use just some clone of xpath because:
> "A string begins and ends with
> quotation marks. All Unicode characters may be placed within the
> quotation marks except for the characters that must be escaped:
> quotation mark, reverse solidus, and the control characters (U+0000
> through U+001F)." from JSON spec - http://www.ietf.org/rfc/rfc4627.txt
>
> I mean there is no way to query JSON without quotation marks and
> escaping of unwanted characters.Then it would look like:
> #/"foo"/"bar"/0
> and that is ugly.
Property segments are to be URI encoded. A property name of "bar/0"
would be referenced with #/bar%2F0, so there is no ambiguity with with
the zero index of the "bar" object (#/bar/0).

I believe JSON Pointers is intended to separately specify the URI
referencing from JSON Schema (hence it being discussed here), and this
is specified in the JSON Schema under the slash delimited resolution
section.

Kris

Reply all
Reply to author
Forward
0 new messages