I'd like to convert hex format data received through web api from Pysun to json through code.

Asked 1 years ago, Updated 1 years ago, 61 views

I'm a student studying blockchain and bitcoin. I got raw block data of bitcoin block through web api as below.

url="https://blockchain.info/rawblock/00000000000000000002447735c7723ee9188322c0938e6587866a4458b9135f?format=hex"

resp = requests.get(url=url)

data = resp.text

If you change the ?format to json at the end of url, you can get json information, but

I would like to receive hex data as above and change hex data to json format through python code.

Is there a code I can change?

Please answer me. Thank you.

python blockchain hex json programming

2022-09-20 21:50

1 Answers

The contents received in format=hex seem to have passed a binary to a hexastring. Generally, you can change a hex string to a binary

from binascii
b = binascii.unhexlify('313233')

in the same way possible.

However, it seems that the string taken from the url as an example in the question is not a string that can be easily replaced by json, but there is another special internal structure. If you don't know the structure, you can't change it to json.

If you really need json, it seems right to just get json's response and write it.


2022-09-20 21:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.