0

I need to get a value of token in below output using python re. Could someone please help me out

I need to get below string:

eyJhbGciOiJIIkpXVCJ9.eyJpc3MiOiIxOWQzODdmZC1kMjA2LTQzNDYtOGRhNy1lMjRkNDZlMWZjZDgiLCJleHAiOjE0OTMwNTA1MxNH0.JBiPb0x4pg_lQXxEV-rbd27qvgm9Q`

Output:

{"token":"eyJhbGciOiJIIkpXVCJ9.eyJpc3MiOiIxOWQzODdmZC1kMjA2LTQzNDYtOGRhNy1lMjRkNDZlMWZjZDgiLCJleHAiOjE0OTMwNTA1MxNH0.JBiPb0x4pg_lQXxEV-rbd27qvgm9Q","refresh_token":"639d4-b4e0-4c-8645-229b9e73a394","expires_in":604800,"user":{"id":"19d-d206-43-8da7-e2cd8","username":"tej123","email":"[email protected]","enabled":true,"updated_email":null,"last_login_at":"2017-04-17T16:14:26.520Z"}}
1
  • 1
    How about using the right tool for the job -- JSON parser? (json.loads(..)["token"]) Commented Apr 18, 2017 at 7:05

1 Answer 1

1

Try:

import json
j = json.loads('{"token":"eyJhbGciOiJIIkpXVCJ9.eyJpc3MiOiIxOWQzODdmZC1kMjA2LTQzNDYtOGRhNy1lMjRkNDZlMWZjZDgiLCJleHAiOjE0OTMwNTA1MxNH0.JBiPb0x4pg_lQXxEV-rbd27qvgm9Q","refresh_token":"639d4-b4e0-4c-8645-229b9e73a394","expires_in":604800,"user":{"id":"19d-d206-43-8da7-e2cd8","username":"tej123","email":"[email protected]","enabled":true,"updated_email":null,"last_login_at":"2017-04-17T16:14:26.520Z"}}')
print(j['token'])
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.