S
S
Stepan Sidorov2020-09-15 18:56:44
Python
Stepan Sidorov, 2020-09-15 18:56:44

How to write .mp3 to JSON?

Hello.
I write in python using the JSON standard library.
I need to write a .mp3 file to JSON, but the problem is that when I try to call json.dumps(), and give it such a dict: I get an error that it is impossible to write bytes. How do I write .mp3 (i.e. byte value) to JSON?
{"file":b"My audio file in bytes"}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2020-09-15
@always-prog

First, you don't have to do this.
Secondly: encode in base64 (or analogues), json is a text format and you cannot shove raw data there.

K
kocherman, 2020-09-15
@kocherman

You can convert, for example, to Base64Uri, for example, here https://base64.guru/converter/encode/file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question