Author |
Message
|
anurag.munjal |
Posted: Thu Jul 13, 2017 4:08 am Post subject: CONTAINS related |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
So, i came accross a requirement where the incoming message structure isnt defined, but we do need to make sure the incoming message does not contain any other character other than 26 pre defined character.
I know of a function called CONTAINS that can check if the attribute in question can check if it contains a char or not,
Quote: |
but is there a way to check if the attribute in question does not contain anything other than the defined 26 chars? |
_________________ - Anurag
------------------------
Be Simple, Be Happy |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jul 13, 2017 4:15 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You say that the incoming message structure isn't defined.
Then you say you want to make sure it matches a very specific definition.
So define the field in the message model and add the necessary validation rules. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
anurag.munjal |
Posted: Thu Jul 13, 2017 4:18 am Post subject: ! |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
So, the incoming message is in hex format! i accept it as a blob and I am converting it into a json using RCD Node without any message model.
do you know if we have any message model that can be build for json validation?
i can maybe add enum values into the field am looking to validate against only a set of chars _________________ - Anurag
------------------------
Be Simple, Be Happy |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jul 13, 2017 4:30 am Post subject: Re: ! |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
anurag.munjal wrote: |
So, the incoming message is in hex format! i accept it as a blob and I am converting it into a json using RCD Node without any message model.
do you know if we have any message model that can be build for json validation?
i can maybe add enum values into the field am looking to validate against only a set of chars |
What does it mean "hex format"?
I don't know if there's support for a message model of a JSON document. I don't even know if there's a standard means of defining a JSON document structure (i.e. something similar to an xsd.). I know there's something, but I forget what, and whether it's standard and supported by IIB.
If it works to use an RCD node to turn it into JSON, then you should be able to tell the input node to just parse it as JSON.
Otherwise the ESQL reference should lead you to the right comparison operator. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
anurag.munjal |
Posted: Thu Jul 13, 2017 4:35 am Post subject: Okay |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Thanks! By hex I mean I am accepting as a blob and then doing some checks on the blob hex data and after that am using a rcd node to convert it into a JSON which works just fine! My query is that is there a dfdl or some message set that can actually check for JSON fields and make sure the values in the JSON do not contain anything other than the defined chars.
CONTAINS Functioning can help me check for presence of characters but I want to check presence of any other characters than the 26 chars which I am ok to allow _________________ - Anurag
------------------------
Be Simple, Be Happy |
|
Back to top |
|
 |
Vitor |
Posted: Thu Jul 13, 2017 4:59 am Post subject: Re: Okay |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
anurag.munjal wrote: |
Thanks! By hex I mean I am accepting as a blob and then doing some checks on the blob hex data and after that am using a rcd node to convert it into a JSON which works just fine! |
This implies that the 'blob' is in fact already a JSON message (because you don't talk about anything doing any transformation, just an RCD). So why take it as a BLOB and then use an RCD? Why not just take it as JSON?
anurag.munjal wrote: |
My query is that is there a dfdl or some message set that can actually check for JSON fields and make sure the values in the JSON do not contain anything other than the defined chars. |
No, because JSON (as described by SWAGGER, YAML, etc) doesn't support such validation. JSON allows a very wide range of characters; if you're trying to artificially restrict it (for no good reason I can think of, in the same way I can't think of a good reason to not treat it as JSON from the get go) then you need to roll your own solution.
anurag.munjal wrote: |
CONTAINS Functioning can help me check for presence of characters but I want to check presence of any other characters than the 26 chars which I am ok to allow |
Which is much easier on parsed JSON than on a BLOB. Which is why I don't understand why you're treating it as a BLOB. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jul 13, 2017 5:14 am Post subject: Re: Okay |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
anurag.munjal wrote: |
CONTAINS Functioning can help me check for presence of characters but I want to check presence of any other characters than the 26 chars which I am ok to allow |
CONTAINS shows you if a *string* exists within another string. (char, blob, etc).
It doesn't tell you that string A contains only some set of characters.
Again, there are other comparison functions. Again, the ESQL reference on comparison functions will show you the one you want.
And if you want to find out if a comparison is false, then you can do the same thing you do in any other programming language. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
Vitor |
Posted: Thu Jul 13, 2017 5:19 am Post subject: Re: Okay |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mqjeff wrote: |
anurag.munjal wrote: |
CONTAINS Functioning can help me check for presence of characters but I want to check presence of any other characters than the 26 chars which I am ok to allow |
CONTAINS shows you if a *string* exists within another string. (char, blob, etc).
It doesn't tell you that string A contains only some set of characters. |
Which I probably should have been clearer on. I was attempting to convey that this kind of string examination is typically easier on parsed JSON than BLOB, and should not have implicitly endorsed your method.
 _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
anurag.munjal |
Posted: Thu Jul 13, 2017 7:07 am Post subject: WOW |
|
|
 Voyager
Joined: 08 Apr 2012 Posts: 97
|
Thanks much for all your responses champs
So, the reason am taking it as blob is that there are some checks that i am doing on the blob like the new line char removal and the removing the null terminator!
So, again - my question is that is there a way to look for a particular field in the json key value pair, and check if this value does not contain anything other than a set of defined characters. _________________ - Anurag
------------------------
Be Simple, Be Happy |
|
Back to top |
|
 |
Vitor |
Posted: Thu Jul 13, 2017 7:15 am Post subject: Re: WOW |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
anurag.munjal wrote: |
So, the reason am taking it as blob is that there are some checks that i am doing on the blob like the new line char removal and the removing the null terminator! |
Still not sure why you need to do that, but moving on.....
anurag.munjal wrote: |
So, again - my question is that is there a way to look for a particular field in the json key value pair |
You either need to use hand-rolled code or ask the JSON parser where the field is once it's been parsed.
anurag.munjal wrote: |
and check if this value does not contain anything other than a set of defined characters. |
I've previously used TRANSLATE for this purpose. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jul 13, 2017 7:16 am Post subject: Re: WOW |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
anurag.munjal wrote: |
So, again - my question is that is there a way to look for a particular field in the json key value pair, |
Yes. They are different ways depending if you have turned the blob into a logical message tree.
anurag.munjal wrote: |
and check if this value does not contain anything other than a set of defined characters. |
Yes. Using the correct comparison function that is documented in the protion of the Knowledge Center that documents ESQL. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
timber |
Posted: Thu Jul 13, 2017 1:38 pm Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
we do need to make sure the incoming message does not contain any other character other than 26 pre defined character. |
Please explain why it is so important to restrict the input characters in this way. Sometimes, these requirements turn out to be invalid. |
|
Back to top |
|
 |
|