1package datautility
2
3import (
4	"fmt"
5	json "github.com/couchbase/indexing/secondary/common/json"
6	tc "github.com/couchbase/indexing/secondary/tests/framework/common"
7)
8
9func LoadJSONFromCompressedFile(path, docidfield string) tc.KeyValues {
10	file, err := tc.ReadCompressedFile(path)
11	tc.HandleError(err, "Error while decompressing data file "+path)
12
13	var data interface{}
14	json.Unmarshal(file, &data)
15
16	m := data.([]interface{})
17	keyValues := make(tc.KeyValues)
18
19	var i = 0
20	var k string
21	if len(docidfield) > 0 {
22		for _, v := range m {
23			k = fmt.Sprintf("%v", v.(map[string]interface{})[docidfield])
24			keyValues[k] = v
25			i++
26		}
27	} else {
28		for _, v := range m {
29			k = fmt.Sprintf("%v", i)
30			keyValues[k] = v
31			i++
32		}
33	}
34
35	return keyValues
36}
37