1//  Copyright (c) 2013 Couchbase, Inc.
2//  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
3//  except in compliance with the License. You may obtain a copy of the License at
4//    http://www.apache.org/licenses/LICENSE-2.0
5//  Unless required by applicable law or agreed to in writing, software distributed under the
6//  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
7//  either express or implied. See the License for the specific language governing permissions
8//  and limitations under the License.
9
10package main
11
12import (
13	"fmt"
14
15	"github.com/couchbase/dparval"
16)
17
18func main() {
19
20	// read some JSON
21	bytes := []byte(`{"type":["test", "this"]}`)
22
23	// create a Value object
24	doc := dparval.NewValueFromBytes(bytes)
25
26	// attempt to access a nested Value
27	docType, err := doc.Path("type")
28	if err != nil {
29		panic("no property type exists")
30	}
31
32	// convert docType to a native go value
33	docTypeValue := docType.Value()
34
35	// display the value
36	fmt.Printf("document type is %v\n", docTypeValue)
37
38	docType, err = docType.Index(1)
39	if err != nil {
40		panic("no index exists")
41	}
42	fmt.Printf("index 1 of type is %v\n", docType.Value())
43}
44