Learner
Learner

Reputation: 571

JSON Representation of HashMap

what is the Json representation of HashMap<String, String>?

I have tried this way but getting bad request error.

"userPreferences":{{"mobile":"yes"},{"email":"yes"}}

Upvotes: 17

Views: 35206

Answers (3)

vidstige
vidstige

Reputation: 13085

"userPreferences":{"mobile":"yes","email":"yes"}

Upvotes: 12

Learner
Learner

Reputation: 571

It should be like this

{ "userPreferences":{"mobile":"yes","email":"yes"} }

Upvotes: 23

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107566

The JSON you have would be invalid even as a JavaScript object, since you haven't defined property names for the two "inner" objects. A HashMap is basically a set of key-value pairs. Your JSON should look like:

"userPreferences": {
    "mobile": "yes",
    "email": "yes"
}

Upvotes: 3

Related Questions