def __next__(self):
        """Iterator method, return next JSON event from the stream, raises
        StopIteration() when complete."""
        while True:
            try:
                token = self.tokens[self.tokenIndex]
                self.tokenIndex += 1
                if token == "" or token.isspace():
                    pass
                elif token == '{':
                    return self._push(OBJECT)
                elif token == '}':
                    if self.node.type == FIELD:
                        self.tokenIndex -= 1
                        event = self._pop()
                        if event is not None:
                            return event
                    elif self.node.type == OBJECT:
                        return self._pop()
                    else:
                        raise JSONParseError(
                            JSON_SYNTAX_ERROR,
                            "A closing curly brace ('}') is only expected "
                            "at the end of an object.")
                elif token == '[':
                    if self.node is not None and self.node.type == OBJECT:
                        raise JSONParseError(
                            JSON_SYNTAX_ERROR, "An array in an object must "
                            "be preceded by a field name.")
                    return self._push(ARRAY)
                elif token == ']':
                    if self.valueType is not None:
                        self.tokenIndex -= 1
                        event = self._arrayValue()
                        if event is not None:
                            return event
                    elif self.node.type == ARRAY:
                        if self.node.lastIndex == self.node.arrayLength:
                            self.node.arrayLength += 1
                        return self._pop()
                    else:
                        raise JSONParseError(
                            JSON_SYNTAX_ERROR, "A closing bracket (']') "
                            "is only expected at the end of an array.")
                elif token == ':':
                    if self.node.type == OBJECT:
                        if self.value != "" and self.valueType == STRING:
                            event = self._push(FIELD, self.value)
                            self.value = ""
                            self.valueType = None
                            return event
                        else:
                            raise JSONParseError(
                                JSON_SYNTAX_ERROR,
                                "Name for name/value pairs cannot be empty.")
                    else:
                        raise JSONParseError(
                            JSON_SYNTAX_ERROR,
                            "A colon (':') can only following a field "
                            "name within an object.")
                elif token == ',':
                    if self.node.type == ARRAY:
                        event = self._arrayValue()
                        self.node.arrayLength += 1
                    elif self.node.type == FIELD:
                        event = self._pop()
                    else:
                        raise JSONParseError(
                            JSON_SYNTAX_ERROR,
                            "A comma (',') is only expected between fields "
                            "in objects or elements of an array.")
                    if event is not None:
                        return event
                else:
                    if self.valueType is not None:
                        raise JSONParseError(
                            JSON_SYNTAX_ERROR, "Extra name or value found "
                            "following: " + str(self.value))
                    elif self.node is None:
                        raise JSONParseError(
                            JSON_SYNTAX_ERROR,
                            "Input must start with either an "
                            "OBJECT ('{') or ARRAY ('['), got '" + token +
                            "' instead.")
                    elif token == '"':
                        escape = False
                        while True:
                            try:
                                token = self.tokens[self.tokenIndex]
                                self.tokenIndex += 1
                                if token == "":
                                    pass
                                elif escape:
                                    escape = False
                                    self.value += token
                                elif token == '"':
                                    break
                                elif token == '\\':
                                    escape = True
                                else:
                                    self.value += token
                            except IndexError:
                                data = self.stream.read(self.size)
                                if data == "":
                                    raise JSONParseError(
                                        JSON_INCOMPLETE_ERROR,
                                        "Reached end of input before " +
                                        "reaching end of string.")
                                self.tokens = self.pattern.split(data)
                                self.tokenIndex = 0
                        self.valueType = STRING
                    else:
                        token = token.strip()
                        if self.tokenIndex == len(self.tokens):
                            self.halfToken = token
                            raise IndexError
                        elif token[0].isdigit() or token[0] == '-':
                            self.value = decimal.Decimal(token)
                            self.valueType = NUMBER
                        elif token == "null":
                            self.value = None
                            self.valueType = NULL
                        elif token == "true":
                            self.value = True
                            self.valueType = BOOLEAN
                        elif token == "false":
                            self.value = False
                            self.valueType = BOOLEAN
                        else:
                            raise JSONParseError(
                                JSON_SYNTAX_ERROR,
                                "Unexpected token: " + token)
            except __HOLE__:
                data = self.stream.read(self.size)
                if data == "":
                    if self.node is not None:
                        raise JSONParseError(
                            JSON_INCOMPLETE_ERROR, "Reached end of input "
                            "before reaching end of JSON structures.")
                    else:
                        raise StopIteration()
                    return None
                logger.trace(data)
                self.tokens = self.pattern.split(data)
                self.tokenIndex = 0
                if self.halfToken is not None:
                    self.tokens[0] = self.halfToken + self.tokens[0]
                    self.halfToken = None
dataset/ETHPy150Open Teradata/PyTd/teradata/pulljson.py/JSONPullParser.__next__