Forum Discussion

Behdad's avatar
Behdad
Occasional Contributor
4 years ago
Solved

Control request characters

Hi  I am new user using readyapi 3.5.0   ðŸ™‚ I have some rest apis with Josn request to test , i need to control the format of every keys value (with string type) in Json request with two main conce...
  • richie's avatar
    4 years ago
    Hey Behdad,

    My answer to the first part is a bit of a guess, but asserting the charset is kindof like asserting the response IS json.
    If i can remember correctly, i believe the RFCs that mention json indicate that all json decoders must support utf-8, so i suggest utf-8 is the default. If it deviates from this i'd hope that the Content-Type header would include some additional detail to the standard 'application/json', so it it was iso-8859-1, i think youd get 'application/json; iso-8859-1' or something equivalent. As far as i'm aware the charset isnt included in the json payload body unlike xml which can include the char encoding in the xml declaration (the first line at the top).


    In regards to asserting every attribute value can only have characters made from a list of characters (that you specified in your message), I think the contains assertion is just for xml, not json so i think you need to use groovy to assert a json attribute has a specific pattern/character list.

    Doing that isnt too difficult except the variation in length. I can assert in groovy that a certain attribute value has a specific pattern and length, i can assert multiple instances of the same attribute has the same pattern and length, but i dont know how to assert the pattern content without specifying the length.
    Even if i got passed the length issue, i would have to include 1 assertion for each uniquely named attribute, cos i dont know how to assert every single attribute value contains only specific characters.

    Perhaps one of the coders (@HimanshuTayal?, ChrisA?, etc.) can help?

    Ta

    Rich