0

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
  • 2
    This sounds very homeworkish. Commented Jul 29, 2010 at 18:18
  • Show the code that you have tried so far. Commented Jul 29, 2010 at 18:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.