Search code examples
pythonlistcompressionencodezlib

is it possible to encode list of objects in python to use it in compress function?


i have a large list and I want to compress it in python using zlib.compress function and decompress it in javascript, in order to compress it, it must be encoded in utf-8, my question is: is it possible to encode it? if not, how I can compress this list in python and decompress it in angular?

list example: [{"name":"value1","y":0.0}, {"name":"value2","y":1.0} , .. ]


Solution

  • You would first need to encode the list into a sequence of bytes that could be interpreted at the other end. JSON might be a good choice in this case, depending on if the list content is suitably constrained. Then use zlib to compress the sequence of bytes.