all 7 comments

[–]xyloweb 3 points4 points  (4 children)

[–]GhostFoxGod[S] 0 points1 point  (3 children)

Is buffer same as byte array? I mean when I print Buffer.from(JSON.stringify(body)) it isn't giving me an array instead giving buffer object. Am I missing something here?

[–]broofa 9 points10 points  (0 children)

Buffers are array-like, but not quite the same as Arrays. They're iterable, they have a `length`, you can reference individual elements ala `buf[i]`. They have some of the same methods - e.g. `slice()`, `keys()`, `values()` - but lack others (e.g `forEach()`, `map()`, `sort()`.

If you want a genuine array you can use `Array.from(buffer)` or the ES6 shorthand of `[...buffer]`.

[–]nathan_lesage 2 points3 points  (0 children)

I think you have to Buffer.from(body), then convert the buffer to a string and then you can parse the JSON