0

I have a basic ASP.NET Web API project. When I send a request, the serialization is done using System.Text.Json. However, when I send a non-valid json, for example text instead of number, it returns a binding validation error:

{
    "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "errors": {
        "model": [
            "The model field is required."
        ],
        "$.items[0].price": [
            "The JSON value could not be converted to System.String. Path: $.items[0].price | LineNumber: 4 | BytePositionInLine: 24."
        ]
    }
}

I'm having a bit of a problem with the name of the property $.items[0].price. It bothers me the character - $. I tried to search if there is any way to make my PropertyNameSolver, but I didn't find anything. I know that you can do a replace in the property name, but I really don't like that...

Is there maybe some elegant way to change the property name and its wording?

Thanks

4
  • $ just stands for the root of the JSON ..... $.items[0].price means: the first items element in the root, and then its price field Commented Jul 21 at 18:54
  • Thank you for response. Yeah, I get that, but I don't want that in there. Commented Jul 21 at 19:47
  • What do you mean by I don't want that in there ? That's just the standard JSON notation of how to address specific elements in a JSON document - that's the way it's defined - whether you want it or not.... Commented Jul 21 at 20:01
  • I'm not entirely sure that's standard. For example, newtonsoft doesn't do it. Commented Jul 22 at 5:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.