Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend array operations to also work on strings #28

Open
mitar opened this issue Oct 12, 2019 · 2 comments
Open

Extend array operations to also work on strings #28

mitar opened this issue Oct 12, 2019 · 2 comments

Comments

@mitar
Copy link

mitar commented Oct 12, 2019

As an alternative to #6 and #25 I would propose that operations are allowed to index into strings as well. This would allow one to modify parts of a string instead of sending the whole value over. Moreover, internally, strings are often seen as something you can index already, or are even arrays of characters.

So for a JSON like:

{"value": "foobar"}

A patch like:

[
  {"op": "replace", "path": "/value/0-3", "value": "no"}
]

Replacing first three characters with "no' and resulting in:

{"value": "nobar"}

So upper limit would be exclusive. You could also specify "2-" to select all characters from the 3rd character to the end.

I would not introduce a whole new set of string operations. And also do note that such pointer is uniquely determined given a type of the value at the path. So if it points to an array, 0-3 index into the array (for now I would leave such index invalid for arrays, but that could be a separate discussion), if it points to a string it index into the string. And if there is an object, it is simply a 0-3 property of the object.

@ucarion
Copy link

ucarion commented Oct 13, 2019

(Let me know if you'd prefer this question be posed in json@ietf.org)

What, in your view, should indexing into strings mean here? Are we indexing into an array of codepoints? Bytes (presuming some particular representation)? Something else?

In other words, what does "character" mean here?

@mitar
Copy link
Author

mitar commented Oct 13, 2019

(Let me know if you'd prefer this question be posed in json@ietf.org)

I think it is good here, I posted a link there to this issue, so I think we can move conversation herje.

What, in your view, should indexing into strings mean here? Are we indexing into an array of codepoints? Bytes (presuming some particular representation)? Something else?

I think that JSON standard already discusses string comparisons by code units, so I think this indexing into strings should be done by code units as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants