Skip to content

Instantly share code, notes, and snippets.

@Igosuki
Last active November 21, 2019 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Igosuki/74c44f6788f17283bffabf5fede64b1e to your computer and use it in GitHub Desktop.
Save Igosuki/74c44f6788f17283bffabf5fede64b1e to your computer and use it in GitHub Desktop.
Reading NodeJS JSON encoded buffers in Python.
const j = '{"type":"Buffer","data":[93,204,151,170,0,0,194,155,10,119,139,1,10,13,41,43]}'
const buffer = Buffer.from(JSON.parse(j).data)
console.log(JSON.stringify(buffer)); // verify that a buffer is stringified as the string above by default
console.log('buffer string value : ' + buffer.toString('hex')) // concat with str
from struct import *
import binascii
import json
json_str = '{"type":"Buffer","data":[93,204,151,170,0,0,194,155,10,119,139,1,10,13,41,43]}'
a = bytearray(json.loads(json_str)['data'])
print(binascii.hexlify(bytearray(a)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment