jsonptr icon indicating copy to clipboard operation
jsonptr copied to clipboard

Potential Support for Regex?

Open JewishLewish opened this issue 2 years ago • 3 comments

Suggestion

Do you think there is the potential of adding Regex? I know there is already a crate for Rust Regex: https://docs.rs/regex/latest/regex/

JewishLewish avatar Oct 20 '23 01:10 JewishLewish

Let me think about that one. It isn't part of the spec and I'm not certain how regex would play with encoding.

chanced avatar Oct 20 '23 16:10 chanced

I don't think regex would play with encoding rather finding the key you are searching for in the Json Ex.

{
  "name": {"first": "Tom", "last": "Anderson"},
  "age":37,
  "children": ["Sara","Alex","Jack"],
  "fav.movie": "Deer Hunter",
  "friends": [
    {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
    {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
    {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
  ]
}
"name.last"          >> "Anderson"
"age"                >> 37
"children"           >> ["Sara","Alex","Jack"]
"children.#"         >> 3
"children.1"         >> "Alex"
"child*.2"           >> "Jack"
"c?ildren.0"         >> "Sara"
"fav\.movie"         >> "Deer Hunter"
"friends.#.first"    >> ["Dale","Roger","Jane"]
"friends.1.last"     >> "Craig"

(note: I'm using gjson as an example)

It isn't required for json encoding, locating or decoding however regex can come useful when it comes to searching data.

JewishLewish avatar Oct 20 '23 17:10 JewishLewish

It isn't the encoding of json but the json pointer itself. There aren't many rules but they'd potentially conflict with regex.

No matter how the expressions were represented, it would be novel. For a lib that's supposed to adhere to a spec, that's likely not ideal.

I'm a fan of gjson / sjson (used them both in go before he ported them to rust) but he doesn't have a spec to follow.

chanced avatar Oct 20 '23 17:10 chanced

I am closing this as I believe it is outside the scope of this crate.

Thank you for the suggestion but the functionality would exceed the specification and add novel behavior.

chanced avatar Jun 14 '24 18:06 chanced