Provide api for building Json Pointers.
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is your feature request related to a problem? Please describe.
The methods of `JsonPatchDocument` accept string `path` parameters which each accept strings with no additional validations.
In order to build various patches a user must build these strings appropriately. In my experience that often means joining a significant number of small strings together repeatedly with something like `var path = prefix + "/" + Utilities.EncodeForJsonPointer(pathitem);`.
Often I have paths where highly accessed short constant string tokens are used repeatedly and I've probably made some poor decisions in how to lay my code out to efficiently produce appropriate responses.
For example I might have a controller method that returns a document like this:
```csharp
public ActionResult DoThing() {
return JsonPatchDocument.Add("/" + Utilities.EncodeForJsonPointer(MyParameterObject.Bindings.DoThing) + "/-", new Thing());
}
```
My utility method here is encoding the property according to https://tools.ietf.org/html/rfc6901, effectively:
```csharp
public static EncodeForJsonPointer(string input) => input.Replace("~", "~0").Replace("/", "~1");
```
### Describe the solution you'd like
It would be nice if there was an easy to use api that provided some guidance on how to make these things.
Having a type that is not `string` in a common namespace that a library author or application dev might reasonably be expected to have at hand would encourage coupling to the improved type and discourage fixating on this primitive form.
### Additional context
At the very least `JsonPatchDocument` utilizes string paths that are expected to be in a well known format yet I cannot find any documentation on starting from https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.jsonpatch.jsonpatchdocument if I didn't already know what I was doing with it.
Contributor guide
Assessment
This issue has not been assessed yet.