This Python script converts a Msgpack binary file into a JSON format.

import msgpack
import json
import sys

if len(sys.argv) < 2:
    print('Usage: python3 msgpack_to_json.py <msgpack_file>')
    sys.exit(1)

msgpack_file = sys.argv[1]

# Open the Msgpack file and read the data
with open(msgpack_file, 'rb') as f:
    data = msgpack.unpack(f, raw=False)

# Convert the data to JSON format and print
json_data = json.dumps(data, indent=4)
print(json_data)

Usage:

  1. Save the above code as a file named 'msgpack_to_json.py'.
  2. Execute the script in the command line using 'python3 msgpack_to_json.py <msgpack_file>', where '<msgpack_file>' is the path to the Msgpack binary file you want to convert.

原文地址: https://www.cveoy.top/t/topic/npbR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录