sretko
sretko

Reputation: 640

jQuery - traversing through Json object

I have the following Json object:

Object {success: false, errors: "{"email": [{"message": "Enter a valid email address.", "code": "invalid"}]}"}

This is response of Django errors.as_jason method. I need to process the error message Enter a valid email address. I'm using jQuery. I tried many ways but with no success. json.errors return this

{"email": [{"message": "Enter a valid email address.", "code": "invalid"}]}

but then json.errors.message return undefined and I didn't find a way to get it correct.

How I can get the message only?

Upvotes: 0

Views: 37

Answers (1)

Sean Kwon
Sean Kwon

Reputation: 907

If errors, in your case, is represented by a string, you may need to do the following:

JSON.parse(json.errors).email[0].message

Well, that's what I'd do, assuming I'm reading your message right.

Upvotes: 2

Related Questions