simc / crimson

Fast, efficient and easy-to-use JSON parser and serializer for Dart.
Apache License 2.0
227 stars 6 forks source link

JSON Pointers single prefix limitation #21

Open chrisgblr opened 1 year ago

chrisgblr commented 1 year ago

Would be very helpful if this limitation could be lifted:

Important: You can only use a pointer prefix once in a class. For example, you can't use /user and /user/name in the same class.

JulianBissekkou commented 1 year ago

@simc Can you explain why that is? I never used json pointers before, but using multiple pointers sounds like a valid use case for me 🤔

simc commented 1 year ago

@JulianBissekkou pointers basically allow you easily and very efficiently unwrap nested json. Check out the example in the readme.

Using a pointer prefix multiple times is definitely a valid use case but very difficult to implement. Crimson has the distinct advantage to only need a single pass to parse bytes directly to objects. To use a prefix multiple times while maintaining the single pass advantage would require a complex state machine to keep track of different paths. I'm currently not sure how to implement it and whether it will be faster or slower than parsing the entire objects.