func stateTr(s *Scanner, c int) int {
	if c == 'u' {
		s.Step = stateTru
		return ScanContinue
	}
	return s.error(c, "in literal true (expecting 'u')")
}
stateTr is the state after reading `tr`.
package json
import "strconv"
func checkValid(data []byte, scan *Scanner) error {
	scan.Reset()
	for _, c := range data {
		scan.bytes++
		if scan.Step(scan, int(c)) == ScanError {
			return scan.Err
		}
	}
	if scan.EOF() == ScanError {
		return scan.Err
	}
	return nil
}
func Validate(data []byte) error {
	s := &Scanner{}
	return checkValid(data, s)
}
func NextValue(data []byte, scan *Scanner) (value, rest []byte, err error) {
	scan.Reset()
	for i, c := range data {
		v := scan.Step(scan, int(c))
		if v >= ScanEnd {
			switch v {
			case ScanError:
				return nil, nil, scan.Err
			case ScanEnd:
				return data[0:i], data[i:], nil
			}
		}
	}
	if scan.EOF() == ScanError {
		return nil, nil, scan.Err
	}
	return data, nil, nil
}
type SyntaxError struct {
	msg    string  
	Offset int64   
}
func (e *SyntaxError) Error() string { return e.msg }
type Scanner struct {
	Step func(*Scanner, int) int
	endTop bool
	parseState []int
	Err error
	redo      bool
	redoCode  int
	redoState func(*Scanner, int) int
	bytes int64
}
const (
	ScanContinue     = iota  
	ScanBeginLiteral         
	ScanBeginObject          
	ScanObjectKey            
	ScanObjectValue          
	ScanEndObject            
	ScanBeginArray           
	ScanArrayValue           
	ScanEndArray             
	ScanSkipSpace            
	ScanEnd    
	ScanError  
)
const (
	parseObjectKey   = iota  
	parseObjectValue         
	parseArrayValue          
)
func (s *Scanner) Reset() {
	s.Step = stateBeginValue
	s.parseState = s.parseState[0:0]
	s.Err = nil
	s.redo = false
	s.endTop = false
}
func (s *Scanner) EOF() int {
	if s.Err != nil {
		return ScanError
	}
	if s.endTop {
		return ScanEnd
	}
	s.Step(s, ' ')
	if s.endTop {
		return ScanEnd
	}
	if s.Err == nil {
		s.Err = &SyntaxError{"unexpected end of JSON input", s.bytes}
	}
	return ScanError
}
func (s *Scanner) pushParseState(p int) {
	s.parseState = append(s.parseState, p)
}
func (s *Scanner) popParseState() {
	n := len(s.parseState) - 1
	s.parseState = s.parseState[0:n]
	s.redo = false
	if n == 0 {
		s.Step = stateEndTop
		s.endTop = true
	} else {
		s.Step = stateEndValue
	}
}
func isSpace(c rune) bool {
	return c == ' ' || c == '\t' || c == '\r' || c == '\n'
}
func stateBeginValueOrEmpty(s *Scanner, c int) int {
	if c <= ' ' && isSpace(rune(c)) {
		return ScanSkipSpace
	}
	if c == ']' {
		return stateEndValue(s, c)
	}
	return stateBeginValue(s, c)
}
func stateBeginValue(s *Scanner, c int) int {
	if c <= ' ' && isSpace(rune(c)) {
		return ScanSkipSpace
	}
	switch c {
	case '{':
		s.Step = stateBeginStringOrEmpty
		s.pushParseState(parseObjectKey)
		return ScanBeginObject
	case '[':
		s.Step = stateBeginValueOrEmpty
		s.pushParseState(parseArrayValue)
		return ScanBeginArray
	case '"':
		s.Step = stateInString
		return ScanBeginLiteral
	case '-':
		s.Step = stateNeg
		return ScanBeginLiteral
	case '0':  
		s.Step = state0
		return ScanBeginLiteral
	case 't':  
		s.Step = stateT
		return ScanBeginLiteral
	case 'f':  
		s.Step = stateF
		return ScanBeginLiteral
	case 'n':  
		s.Step = stateN
		return ScanBeginLiteral
	}
	if '1' <= c && c <= '9' {  
		s.Step = state1
		return ScanBeginLiteral
	}
	return s.error(c, "looking for beginning of value")
}
func stateBeginStringOrEmpty(s *Scanner, c int) int {
	if c <= ' ' && isSpace(rune(c)) {
		return ScanSkipSpace
	}
	if c == '}' {
		n := len(s.parseState)
		s.parseState[n-1] = parseObjectValue
		return stateEndValue(s, c)
	}
	return stateBeginString(s, c)
}
func stateBeginString(s *Scanner, c int) int {
	if c <= ' ' && isSpace(rune(c)) {
		return ScanSkipSpace
	}
	if c == '"' {
		s.Step = stateInString
		return ScanBeginLiteral
	}
	return s.error(c, "looking for beginning of object key string")
}
func stateEndValue(s *Scanner, c int) int {
	n := len(s.parseState)
	if n == 0 {
		s.Step = stateEndTop
		s.endTop = true
		return stateEndTop(s, c)
	}
	if c <= ' ' && isSpace(rune(c)) {
		s.Step = stateEndValue
		return ScanSkipSpace
	}
	ps := s.parseState[n-1]
	switch ps {
	case parseObjectKey:
		if c == ':' {
			s.parseState[n-1] = parseObjectValue
			s.Step = stateBeginValue
			return ScanObjectKey
		}
		return s.error(c, "after object key")
	case parseObjectValue:
		if c == ',' {
			s.parseState[n-1] = parseObjectKey
			s.Step = stateBeginString
			return ScanObjectValue
		}
		if c == '}' {
			s.popParseState()
			return ScanEndObject
		}
		return s.error(c, "after object key:value pair")
	case parseArrayValue:
		if c == ',' {
			s.Step = stateBeginValue
			return ScanArrayValue
		}
		if c == ']' {
			s.popParseState()
			return ScanEndArray
		}
		return s.error(c, "after array element")
	}
	return s.error(c, "")
}
func stateEndTop(s *Scanner, c int) int {
	if c != ' ' && c != '\t' && c != '\r' && c != '\n' {
		s.error(c, "after top-level value")
	}
	return ScanEnd
}
func stateInString(s *Scanner, c int) int {
	if c == '"' {
		s.Step = stateEndValue
		return ScanContinue
	}
	if c == '\\' {
		s.Step = stateInStringEsc
		return ScanContinue
	}
	if c < 0x20 {
		return s.error(c, "in string literal")
	}
	return ScanContinue
}
func stateInStringEsc(s *Scanner, c int) int {
	switch c {
	case 'b', 'f', 'n', 'r', 't', '\\', '/', '"':
		s.Step = stateInString
		return ScanContinue
	}
	if c == 'u' {
		s.Step = stateInStringEscU
		return ScanContinue
	}
	return s.error(c, "in string escape code")
}
func stateInStringEscU(s *Scanner, c int) int {
	if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
		s.Step = stateInStringEscU1
		return ScanContinue
	}
	return s.error(c, "in \\u hexadecimal character escape")
}
func stateInStringEscU1(s *Scanner, c int) int {
	if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
		s.Step = stateInStringEscU12
		return ScanContinue
	}
	return s.error(c, "in \\u hexadecimal character escape")
}
func stateInStringEscU12(s *Scanner, c int) int {
	if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
		s.Step = stateInStringEscU123
		return ScanContinue
	}
	return s.error(c, "in \\u hexadecimal character escape")
}
func stateInStringEscU123(s *Scanner, c int) int {
	if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
		s.Step = stateInString
		return ScanContinue
	}
	return s.error(c, "in \\u hexadecimal character escape")
}
func stateNeg(s *Scanner, c int) int {
	if c == '0' {
		s.Step = state0
		return ScanContinue
	}
	if '1' <= c && c <= '9' {
		s.Step = state1
		return ScanContinue
	}
	return s.error(c, "in numeric literal")
}
func state1(s *Scanner, c int) int {
	if '0' <= c && c <= '9' {
		s.Step = state1
		return ScanContinue
	}
	return state0(s, c)
}
func state0(s *Scanner, c int) int {
	if c == '.' {
		s.Step = stateDot
		return ScanContinue
	}
	if c == 'e' || c == 'E' {
		s.Step = stateE
		return ScanContinue
	}
	return stateEndValue(s, c)
}
func stateDot(s *Scanner, c int) int {
	if '0' <= c && c <= '9' {
		s.Step = stateDot0
		return ScanContinue
	}
	return s.error(c, "after decimal point in numeric literal")
}
func stateDot0(s *Scanner, c int) int {
	if '0' <= c && c <= '9' {
		s.Step = stateDot0
		return ScanContinue
	}
	if c == 'e' || c == 'E' {
		s.Step = stateE
		return ScanContinue
	}
	return stateEndValue(s, c)
}
func stateE(s *Scanner, c int) int {
	if c == '+' {
		s.Step = stateESign
		return ScanContinue
	}
	if c == '-' {
		s.Step = stateESign
		return ScanContinue
	}
	return stateESign(s, c)
}
func stateESign(s *Scanner, c int) int {
	if '0' <= c && c <= '9' {
		s.Step = stateE0
		return ScanContinue
	}
	return s.error(c, "in exponent of numeric literal")
}
func stateE0(s *Scanner, c int) int {
	if '0' <= c && c <= '9' {
		s.Step = stateE0
		return ScanContinue
	}
	return stateEndValue(s, c)
}
func stateT(s *Scanner, c int) int {
	if c == 'r' {
		s.Step = stateTr
		return ScanContinue
	}
	return s.error(c, "in literal true (expecting 'r')")
}