function parseTree(text, errors, options) {
        if (errors === void 0) { errors = []; }
        var currentParent = { type: 'array', offset: -1, length: -1, children: [], parent: void 0 }; // artificial root
        function ensurePropertyComplete(endOffset) {
            if (currentParent.type === 'property') {
                currentParent.length = endOffset - currentParent.offset;
                currentParent = currentParent.parent;
            }
        }
        function onValue(valueNode) {
            currentParent.children.push(valueNode);
            return valueNode;
        }
        var visitor = {
            onObjectBegin: function (offset) {
                currentParent = onValue({ type: 'object', offset: offset, length: -1, parent: currentParent, children: [] });
            },
            onObjectProperty: function (name, offset, length) {
                currentParent = onValue({ type: 'property', offset: offset, length: -1, parent: currentParent, children: [] });
                currentParent.children.push({ type: 'string', value: name, offset: offset, length: length, parent: currentParent });
            },
            onObjectEnd: function (offset, length) {
                currentParent.length = offset + length - currentParent.offset;
                currentParent = currentParent.parent;
                ensurePropertyComplete(offset + length);
            },
            onArrayBegin: function (offset, length) {
                currentParent = onValue({ type: 'array', offset: offset, length: -1, parent: currentParent, children: [] });
            },
            onArrayEnd: function (offset, length) {
                currentParent.length = offset + length - currentParent.offset;
                currentParent = currentParent.parent;
                ensurePropertyComplete(offset + length);
            },
            onLiteralValue: function (value, offset, length) {
                onValue({ type: getLiteralNodeType(value), offset: offset, length: length, parent: currentParent, value: value });
                ensurePropertyComplete(offset + length);
            },
            onSeparator: function (sep, offset, length) {
                if (currentParent.type === 'property') {
                    if (sep === ':') {
                        currentParent.colonOffset = offset;
                    }
                    else if (sep === ',') {
                        ensurePropertyComplete(offset);
                    }
                }
            },
            onError: function (error, offset, length) {
                errors.push({ error: error, offset: offset, length: length });
            }
        };
        visit(text, visitor, options);
        var result = currentParent.children[0];
        if (result) {
            delete result.parent;
        }
        return result;
    }
/**
     * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
     */
Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
Parses the given text and returns a tree representation the JSON content . On invalid input the parser tries to be as fault tolerant as possible but still return a result .
function parseTree(text, errors, options) {
        if (errors === void 0) { errors = []; }
        var currentParent = { type: 'array', offset: -1, length: -1, children: [], parent: void 0 }; 
        function ensurePropertyComplete(endOffset) {
            if (currentParent.type === 'property') {
                currentParent.length = endOffset - currentParent.offset;
                currentParent = currentParent.parent;
            }
        }
        function onValue(valueNode) {
            currentParent.children.push(valueNode);
            return valueNode;
        }
        var visitor = {
            onObjectBegin: function (offset) {
                currentParent = onValue({ type: 'object', offset: offset, length: -1, parent: currentParent, children: [] });
            },
            onObjectProperty: function (name, offset, length) {
                currentParent = onValue({ type: 'property', offset: offset, length: -1, parent: currentParent, children: [] });
                currentParent.children.push({ type: 'string', value: name, offset: offset, length: length, parent: currentParent });
            },
            onObjectEnd: function (offset, length) {
                currentParent.length = offset + length - currentParent.offset;
                currentParent = currentParent.parent;
                ensurePropertyComplete(offset + length);
            },
            onArrayBegin: function (offset, length) {
                currentParent = onValue({ type: 'array', offset: offset, length: -1, parent: currentParent, children: [] });
            },
            onArrayEnd: function (offset, length) {
                currentParent.length = offset + length - currentParent.offset;
                currentParent = currentParent.parent;
                ensurePropertyComplete(offset + length);
            },
            onLiteralValue: function (value, offset, length) {
                onValue({ type: getLiteralNodeType(value), offset: offset, length: length, parent: currentParent, value: value });
                ensurePropertyComplete(offset + length);
            },
            onSeparator: function (sep, offset, length) {
                if (currentParent.type === 'property') {
                    if (sep === ':') {
                        currentParent.colonOffset = offset;
                    }
                    else if (sep === ',') {
                        ensurePropertyComplete(offset);
                    }
                }
            },
            onError: function (error, offset, length) {
                errors.push({ error: error, offset: offset, length: length });
            }
        };
        visit(text, visitor, options);
        var result = currentParent.children[0];
        if (result) {
            delete result.parent;
        }
        return result;
    }
function parseTree ( text , errors , options ) { if ( errors === void 0 ) { errors = [ ] ; } var currentParent = { type : 'array' , offset : - 1 , length : - 1 , children : [ ] , parent : void 0 } ; function ensurePropertyComplete ( endOffset ) { if ( currentParent . type === 'property' ) { currentParent . length = endOffset - currentParent . offset ; currentParent = currentParent . parent ; } } function onValue ( valueNode ) { currentParent . children . push ( valueNode ) ; return valueNode ; } var visitor = { onObjectBegin : function ( offset ) { currentParent = onValue ( { type : 'object' , offset : offset , length : - 1 , parent : currentParent , children : [ ] } ) ; } , onObjectProperty : function ( name , offset , length ) { currentParent = onValue ( { type : 'property' , offset : offset , length : - 1 , parent : currentParent , children : [ ] } ) ; currentParent . children . push ( { type : 'string' , value : name , offset : offset , length : length , parent : currentParent } ) ; } , onObjectEnd : function ( offset , length ) { currentParent . length = offset + length - currentParent . offset ; currentParent = currentParent . parent ; ensurePropertyComplete ( offset + length ) ; } , onArrayBegin : function ( offset , length ) { currentParent = onValue ( { type : 'array' , offset : offset , length : - 1 , parent : currentParent , children : [ ] } ) ; } , onArrayEnd : function ( offset , length ) { currentParent . length = offset + length - currentParent . offset ; currentParent = currentParent . parent ; ensurePropertyComplete ( offset + length ) ; } , onLiteralValue : function ( value , offset , length ) { onValue ( { type : getLiteralNodeType ( value ) , offset : offset , length : length , parent : currentParent , value : value } ) ; ensurePropertyComplete ( offset + length ) ; } , onSeparator : function ( sep , offset , length ) { if ( currentParent . type === 'property' ) { if ( sep === ':' ) { currentParent . colonOffset = offset ; } else if ( sep === ',' ) { ensurePropertyComplete ( offset ) ; } } } , onError : function ( error , offset , length ) { errors . push ( { error : error , offset : offset , length : length } ) ; } } ; visit ( text , visitor , options ) ; var result = currentParent . children [ 0 ] ; if ( result ) { delete result . parent ; } return result ; }
Parses the given text and returns a tree representation the JSON content.
Parses the given text and returns a tree representation the JSON content .
// artificial root