Javascript: convert ArrayBuffer to JSON and otherwise


ArrayBuffer to Array:

var newArray = Array.from(new Uint8Array(arrayBuffer));

Now you can JSON encode with Array

var data = {file: newArrray,name: "my file"}
var string = JSON.stringify(data)

JSON decode to Array:

var newArray = JSON.parse(string)

Array to ArrayBuffer:

var arrayBuffer =new Uint8Array(newArray).buffer

Leave a Reply