Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Non-object JSON roots
Browse files Browse the repository at this point in the history
Updated parser to emit the `root` event for the top-level JSON value, not just objects & arrays.
  • Loading branch information
jpage-godaddy committed Nov 22, 2014
1 parent 468b1fd commit 9a880fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
node_modules/*
npm_debug.log
.idea
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ exports.parse = function (path, map) {
if(!path || !path.length)
path = null

parser.onValue = function () {
if (!this.root && this.stack.length == 1)
stream.root = this.value
parser.onValue = function (value) {
if (!this.root)
stream.root = value

if(! path) return

Expand Down
16 changes: 16 additions & 0 deletions test/non_object_roots.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var JSONStream = require('../');
var it = require('it-is');
var parser = JSONStream.parse();

var succeeded = false;

parser.on('root', function (value) {
it(value).equal(true);
succeeded = true;
});

parser.on('end', function() {
it(succeeded).equal(true);
});

parser.end('true');

0 comments on commit 9a880fc

Please sign in to comment.