Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if all " characters in a string are escaped

Tags:

java

json

I haven't found anything online that could help me or maybe it is my knowledge in Regex expressions that hinder.

I would like to check if all " characters in a string are escaped. Take this string for example.

\"\"This is the first sentence\"
\"This is the second sentence\"
\"This is the third sentence\"\"
like image 641
Jake Mission Avatar asked Nov 28 '25 13:11

Jake Mission


1 Answers

Add a leading [" and trailing "] to the string, then attempt to parse it as JSON. If everything is properly escaped there will be no parse errors. You can use an online parser such as the one at http://json.parser.online.fr/ , if you want check a string from source, without running code.

like image 188
Hot Licks Avatar answered Dec 01 '25 06:12

Hot Licks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!