MCPcopy Create free account
hub / github.com/bcicen/jstream / array

Method array

decoder.go:418–456  ·  view source on GitHub ↗

array accept valid JSON array value

()

Source from the content-addressed store, hash-verified

416
417// array accept valid JSON array value
418func (d *Decoder) array() ([]interface{}, error) {
419 d.depth++
420
421 var (
422 c byte
423 v interface{}
424 err error
425 array = make([]interface{}, 0)
426 )
427
428 // look ahead for ] - if the array is empty.
429 if c = d.skipSpaces(); c == ']' {
430 goto out
431 }
432
433scan:
434 if v, err = d.emitAny(); err != nil {
435 goto out
436 }
437
438 if d.depth > d.emitDepth { // skip alloc for array if it won't be emitted
439 array = append(array, v)
440 }
441
442 // next token must be ',' or ']'
443 switch c = d.skipSpaces(); c {
444 case ',':
445 d.skipSpaces()
446 goto scan
447 case ']':
448 goto out
449 default:
450 err = d.mkError(ErrSyntax, "after array element")
451 }
452
453out:
454 d.depth--
455 return array, err
456}
457
458// object accept valid JSON array value
459func (d *Decoder) object() (map[string]interface{}, error) {

Callers 1

anyMethod · 0.95

Calls 3

skipSpacesMethod · 0.95
emitAnyMethod · 0.95
mkErrorMethod · 0.95

Tested by

no test coverage detected