tags:

views:

51

answers:

1

Hi,

I've the following strings which I would like to decode into different variables depending on the string

examples

{"response":{"report":"fail","brand":"1.0","fail":{"message":"Invalid Number"}}}

{"response":{"report" : "pass", "brand" : "1.0", "payment" :{"paymentId":"4CA008DAAA41EC19C754EF"}}}

{"response":{"report":"fail","brand":"1.0","fail":{"message":"internal server problems."}}}

{"response" : {"report" : "pass", "brand" : "1.0", "email" :{"subject":"Notification","to":"[email protected]"}}}

I want to get one liner command or multiple command to fetch values into different variables.

Results

Variable 1 = fail  variable 2 = 1.0 variable 3 = Invalid Number

Variable 1 = pass  variable 2 = 1.0 variable 3 = 4CA008DAAA41EC19C754EF

Variable 1 = fail  variable 2 = 1.0  variable 3 = internal server problems.

variabl 1 = pass variable 2 = 1.0 variable 3 = Notification variable 4 = [email protected]  ( since there are 2 values in the inner most {} )
+2  A: 

Try to use a proper JSON decoder like http://search.cpan.org/perldoc?JSON

Even if eval() works (which I kinda doubt), it's rather unsafe, and can execute arbitrary code on your machine. Ouch.

moritz