Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including binary-extract with all npm packages installed. Try it out:

var binaryExtract = require("binary-extract")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

binary-extract v0.1.1

Extract values from a binary json blob


Extract one or more values from a buffer of json without parsing the whole thing.

build status


var extract = require('binary-extract');

var buf = new Buffer(JSON.stringify({
  foo: 'bar',
  bar: 'baz',
  nested: {
    bar: 'nope'  

var value = extract(buf, 'bar');
// => 'baz'

var values = extract(buf, ['foo', 'nested'])
// => ["bar", {"bar":"nope"}]


With the object from bench.js, extract() is ~2-4x faster than JSON.parse(buf.toString()). It is also way more memory efficient as the blob stays out of the V8 heap.

The big perf gain comes mainly from not parsing everything and not converting the buffer to a string.


$ npm install binary-extract


extract(buf, keys)

Extract the value of keys in the json buf.

The value can be any valid JSON structure.

If keys is a String, returns a value. If keys is an Array of keys, returns an array of values.




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free