networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
807 stars 320 forks source link

How to obtain the specific value of an element in the path of abnormal information #984

Closed Dloadinghao closed 4 months ago

Dloadinghao commented 4 months ago

For example, my error message is : $.doc.schema _ query.dimensions [ 1 ] : xxxxxxxx, whether there is a built-in method to set the value of the index 1 directly returned to the dimensions array, rather than the specific index value.

justin-tay commented 4 months ago

I don't really understand what you mean by set the value to the dimensions array.

If it helps the validation message contains the instanceNode that the instanceLocation points to. Note that if the keyword applies to an object or array the instanceNode will then be the object or array. For example the required and additionalProperties keywords are going to be pointing to an object.

Dloadinghao commented 4 months ago

I don't really understand what you mean by set the value to the dimensions array.

If it helps the validation message contains the instanceNode that the instanceLocation points to. Note that if the keyword applies to an object or array the instanceNode will then be the object or array. For example the required and additionalProperties keywords are going to be pointing to an object.

I 'm sorry, I 'm not good at English, which causes ambiguity in expression. For example, the name of the element with an index of 1 under the $.doc.schema query.dimensions group is server ip. I hope to display the value of server ip in the abnormal information, and the expected value is : $.doc.schema query.dimensions [ server_ip ]

justin-tay commented 4 months ago

The $.doc.schema_query.dimensions[1] is the instanceLocation where the error has occurred so I don't know what you mean by $.doc.schema_query.dimensions[server_ip]. It would be clearer if you actually provided your schema, input data the actual message and what your expectations are, but it is unlikely that there is a built-in mechanism for what you want.

In this case you can get the value of $.doc.schema_query.dimensions[1] from instanceNode. If you want to incorporate the value into your message you will have to do some string manipulation of the message.