Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape "[" bracket from json

Tags:

java

json

I know that "[" brackets are used in json to specify a list such as: "Value":["A","B"]

However I want to use those brackets as is in json like "Value":"[A TO B]" since in the future this json string gets mapped to a URL:

I am using java where while using json parser it gives me an error. Is there a way I can escape "[" brackets.

like image 266
happa Avatar asked Dec 02 '25 15:12

happa


1 Answers

As long as you keep it in quotes, it is valid JSON. Try the code below in a validator

{
    "key": "mykey",
    "Value": "[A TO B]"
}

It returns: valid!

like image 130
blurfus Avatar answered Dec 04 '25 07:12

blurfus



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!