Subject: [apps-discuss] JSON pointer: allow /7, but not /07, as an array index

From: "Manger, James H" <[email-masked]>
Date: Thu, 10 Jan 2013 01:08:16 +1100

Can I again ask that we disallow unnecessary leading zeros in array indices in JSON pointers.

An extra reason is to make it easier to be able to tell when one pointer is a “proper prefix” of another, and to make this test possible without needing the context of a specific JSON text.
For example, is /foo/07/bar a “proper prefix” (pointer to a parent) of /foo/7/bar/xxx?
Currently it might be, or it might not be – depending on whether the value of /foo is an array or an object.
This unnecessary complicates code that want to implement the “move” operation in json-patch, which says the “from” location MUST NOT be a proper prefix of the “path” location.

[For other reasons (and suggested text) see an earlier thread: http://www.ietf.org/mail-archive/web/apps-discuss/current/msg07725.html]

--
James Manger

---

From: Nico Williams <[email-masked]>
Date: Wed, 16 Jan 2013 14:01:37 -0600

> Can I again ask that we disallow unnecessary leading zeros in array indices

But it could be a dict key.

Nico
--

---

From: Matthew Morley <[email-masked]>
Date: Wed, 16 Jan 2013 22:39:51 -0500

On Wed, Jan 16, 2013 at 3:01 PM, Nico Williams <[email-masked]>wrote:

> > Can I again ask that we disallow unnecessary leading zeros in array
> indices
> > in JSON pointers.
>

For me, this is why leading zeros should not be supported. Leading zeros in
a python dict will map to the same value:
>>> dict([(7,'a'), (07,'b')])
{7: 'b'}

At the same time, it is worth noting that JSON pointers cannot represent
all of the possible keys of a python dict to begin with, as JSON itself
does not.
>>> json.dumps(dict([(7,'a'), (07,'b'), ('7', 'c'), ('07', 'd')]))
'{"07": "d", "7": "c", "7": "b"}'

-- 
Matt (MPCM)

---

From: Nico Williams <[email-masked]>
Date: Wed, 16 Jan 2013 21:47:01 -0600

> a python dict will map to the same value:

This isn't Python.  It's JSON, and keys must be strings.

And looking at the latest I-D leading zeros are forbidden, but only
when a component names an array index, which is exactly what I want.

Nico
--

---

From: Matthew Morley <[email-masked]>
Date: Wed, 16 Jan 2013 23:22:08 -0500

On Wed, Jan 16, 2013 at 10:47 PM, Nico Williams <[email-masked]>wrote:

> when a component names an array index, which is exactly what I want
>

We are in agreement, I misunderstood your original post.

-- 
Matt (MPCM)

---

From: William Mills <[email-masked]>
Date: Wed, 16 Jan 2013 21:55:31 -0800 (PST)

+1.  Anyone using atoi() will get collisions.  Allowing leading zeroes is bad.  in fact you should make sure you have a very strict integer >=0 definition.  Something like [0-9]/[1/9][0-9]+

>________________________________
> From: Matthew Morley <[email-masked]>
>To: Nico Williams <[email-masked]> 
>Cc: IETF Apps Discuss <[email-masked]> 
>Sent: Wednesday, January 16, 2013 7:39 PM
>Subject: Re: [apps-discuss] JSON pointer: allow /7, but not /07, as an array index
> 
>
>On Wed, Jan 16, 2013 at 3:01 PM, Nico Williams <[email-masked]> wrote:
>
>For me, this is why leading zeros should not be supported. Leading zeros in a python dict will map to the same value:
>
>At the same time, it is worth noting that JSON pointers cannot represent all of the possible keys of a python dict to begin with, as JSON itself does not.
>_______________________________________________
>apps-discuss mailing list
>[email-masked]
>https://www.ietf.org/mailman/listinfo/apps-discuss
>
>
>

---

From: Nico Williams <[email-masked]>
Date: Thu, 17 Jan 2013 00:05:22 -0600

On Wed, Jan 16, 2013 at 11:55 PM, William Mills <[email-masked]> wrote:
> +1.  Anyone using atoi() will get collisions.  Allowing leading zeroes is
> bad.  in fact you should make sure you have a very strict integer >=0
> definition.  Something like [0-9]/[1/9][0-9]+

The I-D already says no leading zeros allowed when indexing arrays.