cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1083
Views
0
Helpful
4
Replies

How to convert a

1pdemharter
Level 1
Level 1

Hi all,

 

I did a REST API call and I get a response like this:

 

result = b [{"id":"865776","name":"Cisco","url":"https://abc.com}]"]

 

I learned, that this is binary object (bold b), but I couldn't find anything to convert.

My question is:

How could I convert this in a Python List/Dictionary, to work on it with the normal

Python List/Dictionary commands?

 

Many thx in advance

 

Peter

 

 

 

 

1 Accepted Solution

Accepted Solutions

The return normally is string.

If the response is byte-like result ----

 

response = b'[{"id":"865776","name":"Cisco","url":"https://abc.com}]"}]'   -- there are some syntax error in the example ,I added some character (assume that is what you mean)

 

Convert to string:

response.decode()  --- default is utf-8 to string.

 

Convert to list

response_list = eval(response.decode())

 

Read the list/dict

response_list[0]['id']

response_list[0]['url]

 

HTH.

View solution in original post

4 Replies 4

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi,

Could you give more details on the request you did? What application/language do you use for your request? Can you share the response as you see it?

 

Regards,

Sergiu

Hi,

 

it was REST API (post/get) call against Meraki and I use Python 3. 

 

Peter

The return normally is string.

If the response is byte-like result ----

 

response = b'[{"id":"865776","name":"Cisco","url":"https://abc.com}]"}]'   -- there are some syntax error in the example ,I added some character (assume that is what you mean)

 

Convert to string:

response.decode()  --- default is utf-8 to string.

 

Convert to list

response_list = eval(response.decode())

 

Read the list/dict

response_list[0]['id']

response_list[0]['url]

 

HTH.

Hi,

 

my tkx. Yes you right there a typo in my example at the end.

 

Peter