3

I have a JSON free text field that allows maximum 1000 characters.

I want to check whether user is able to send paragraphs, so when I parse the text to string using online tools some extra characters like \n\r are coming up.

After this character counter tools shows more than 1000 character after converting text to JSON string but still the request works successfully and doesn't throw error which was expected as character count is showing more than 1000.

I am not sure how to count the max character in JSON. Could some one help me?

3
  • 1
    There are endless ways to achieve that, do you want online tools ? Linux command line ? programming language ? – Rsf Aug 20 '20 at 9:04
  • @Rsf i am new to programming and this was an urgent requirement – sathishS Sep 1 '20 at 9:25
  • COuld you suggest some tools – sathishS Sep 1 '20 at 9:25
3

Json won't support multiline string, so you have to stringify free text before sending, (meaning convert space, tab etc to equivalent escape characters like \n, \t etc)

You can use the below site to stringify text to JSON string:

https://onlinetexttools.com/json-stringify-text

You can use below online website for character count:

https://charactercounttool.com/

Steps for Max validation:

  1. Use the character tool to get paragraph with 1000 character count
  2. Copy the text to the Json stringify website and convert

Note:

If you recount the stringified text you will get more characters , as characters like space, tab etc. are escaped with escape character like \n, \t etc.

So the character count will count two character for \n : which is \ and n, but for the json it will consider \n as single character (space).

So find the text with 1000 characters and then stringify it, don't recount again, just add extra character to the stringified text and validate that error message is thrown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.