// Reads json file recursively returning string
511513
func RenderJSON(c *cli.Context) string {
	filePath := c.GlobalString("gossfile")
	varsFile := c.GlobalString("vars")
	debug = c.Bool("debug")
	TemplateFilter = NewTemplateFilter(varsFile)
	path := filepath.Dir(filePath)
	OutStoreFormat = getStoreFormatFromFileName(filePath)
	gossConfig := mergeJSONData(ReadJSON(filePath), 0, path)

	b, err := marshal(gossConfig)
	if err != nil {
		log.Fatalf("Error rendering: %v\n", err)
	}
	return string(b)
}
33508
func ReadJSON(resp *http.Response, out interface{}) error {
	defer resp.Body.Close()

	if resp.StatusCode >= 400 {
		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return err
		}

		return fmt.Errorf("StatusCode: %d, Body: %s", resp.StatusCode, body)
	}

	if out == nil {
		io.Copy(ioutil.Discard, resp.Body)
		return nil
	}

	decoder := json.NewDecoder(resp.Body)
	return decoder.Decode(out)
}
1017615
func NewJSONSourceFromFile(f string) (InputSourceContext, error) {
	data, err := loadDataFrom(f)
	if err != nil {
		return nil, err
	}
	return NewJSONSource(data)
}
960607
func (d *Dir) ReadFile(subPath string) ([]byte, error) {
	node, err := d.GetByPath(subPath)
	if err != nil {
		return nil, err
	}
	if node.IsDir() {
		return nil, fmt.Errorf("Use ReadFile on directory ")
	}
	var fileNode = node.(*File)
	return fileNode.GetData(), nil
}
64582
func JSON(reader io.Reader) (ABI, error) {
	dec := json.NewDecoder(reader)

	var abi ABI
	if err := dec.Decode(&abi); err != nil {
		return ABI{}, err
	}

	return abi, nil
}
435525
func ReadKVStrings(files []string, override []string) ([]string, error) {
	return readKVStrings(files, override, nil)
}
152721
func jsonnet_evaluate_file(vmRef *C.struct_JsonnetVm, filename *C.char, e *C.int) *C.char {
	f := C.GoString(filename)
	data, err := ioutil.ReadFile(f)
	if err != nil {
		*e = 1
		// TODO(sbarzowski) make sure that it's ok allocation-wise
		return C.CString(fmt.Sprintf("Failed to read input file: %s: %s", f, err.Error()))
	} else {
		return evaluateSnippet(vmRef, f, string(data), e)
	}
}
464152
func LoadJSON(filename string) *Graph {
	js, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil
	}
	return ParseJSON(js)
}
955246
func GetJSON(dat *string, s interface{}) error {
	return json.Unmarshal([]byte(*dat), s)
}
1372270
func jsonToText(scope interface{}, depth int) string {
	var result string

	switch val := scope.(type) {
	case string:
		if strings.ContainsAny(val, "\" \n\t\r") {
			result += `"` + strings.Replace(val, "\"", "\\\"", -1) + `"`
		} else {
			result += val
		}
	case int:
		result += strconv.Itoa(val)
	case float64:
		result += fmt.Sprintf("%v", val)
	case bool:
		result += fmt.Sprintf("%t", val)
	case [][]interface{}:
		result += " {\n"
		for _, arg := range val {
			result += strings.Repeat("\t", depth) + jsonToText(arg, depth+1) + "\n"
		}
		result += strings.Repeat("\t", depth-1) + "}"
	case []interface{}:
		for i, v := range val {
			if block, ok := v.([]interface{}); ok {
				result += "{\n"
				for _, arg := range block {
					result += strings.Repeat("\t", depth) + jsonToText(arg, depth+1) + "\n"
				}
				result += strings.Repeat("\t", depth-1) + "}"
				continue
			}
			result += jsonToText(v, depth)
			if i < len(val)-1 {
				result += " "
			}
		}
	}

	return result
}
590720
func (iter *Iterator) ReadStringAsSlice() (ret []byte) {
	c := iter.nextToken()
	if c == '"' {
		for i := iter.head; i < iter.tail; i++ {
			// require ascii string and no escape
			// for: field name, base64, number
			if iter.buf[i] == '"' {
				// fast path: reuse the underlying buffer
				ret = iter.buf[iter.head:i]
				iter.head = i + 1
				return ret
			}
		}
		readLen := iter.tail - iter.head
		copied := make([]byte, readLen, readLen*2)
		copy(copied, iter.buf[iter.head:iter.tail])
		iter.head = iter.tail
		for iter.Error == nil {
			c := iter.readByte()
			if c == '"' {
				return copied
			}
			copied = append(copied, c)
		}
		return copied
	}
	iter.ReportError("ReadStringAsSlice", `expects " or n, but found `+string([]byte{c}))
	return
}
460019
func (c *ConfigParser) recursiveReadJSON(configPath string) (decodedObject map[string]interface{}, err error) {
	if configPath != "" {
		absConfigPath, err := filepath.Abs(configPath)
		if err != nil {
			return nil, fmt.Errorf("Failed to expand absolute path for %s", configPath)
		}
		if c.touchedFiles[absConfigPath] {
			return nil, fmt.Errorf("ConfigParser include cycle detected reading config: %v",
				absConfigPath)
		}
		c.touchedFiles[absConfigPath] = true

		c.includeStack.Push(absConfigPath)
		defer c.includeStack.Pop()
	}

	var f File
	if f, err = c.open(configPath); err != nil {
		return nil, fmt.Errorf("Failed to open config: %v", err)
	}
	defer f.Close()

	decodedObject = make(map[string]interface{})
	dj := json.NewDecoder(f)
	if err = dj.Decode(&decodedObject); err != nil {
		extra := ""
		if serr, ok := err.(*json.SyntaxError); ok {
			if _, serr := f.Seek(0, os.SEEK_SET); serr != nil {
				log.Fatalf("seek error: %v", serr)
			}
			line, col, highlight := errorutil.HighlightBytePosition(f, serr.Offset)
			extra = fmt.Sprintf(":\nError at line %d, column %d (file offset %d):\n%s",
				line, col, serr.Offset, highlight)
		}
		return nil, fmt.Errorf("error parsing JSON object in config file %s%s\n%v",
			f.Name(), extra, err)
	}

	if err = c.evaluateExpressions(decodedObject, nil, false); err != nil {
		return nil, fmt.Errorf("error expanding JSON config expressions in %s:\n%v",
			f.Name(), err)
	}

	return decodedObject, nil
}
130611
func (c *ConfigParser) ReadFile(path string) (Obj, error) {
	if path == "" && c.Open == nil {
		return nil, errors.New("ReadFile of empty string but Open hook not defined")
	}
	c.touchedFiles = make(map[string]bool)
	var err error
	c.rootJSON, err = c.recursiveReadJSON(path)
	return c.rootJSON, err
}
967216
func ApplyJsonConfigFile(file string) error {
	bin, err := ioutil.ReadFile(file)
	if err != nil {
		return err
	}
	decoder := json.NewDecoder(bytes.NewBuffer(bin))
	decoder.UseNumber()
	var conf Conf
	if err = decoder.Decode(&conf); err != nil {
		return err
	}
	return DictConfig(&conf)
}
241580
func LoadJSON(path string, marshal json.Unmarshaler) error {
	j := NewJSON(path, marshal)
	watch(j)
	j.Load()
	return j.err
}
237365
func (f *JSONFormatter) Read(r *http.Request, v interface{}) error {
	decoder := json.NewDecoder(r.Body)
	return decoder.Decode(v)
}
733505
func parseJSON(inputData []byte) (*jsongo.JSONNode, error) {
	root := jsongo.JSONNode{}

	if err := json.Unmarshal(inputData, &root); err != nil {
		return nil, fmt.Errorf("unmarshalling JSON failed: %v", err)
	}

	return &root, nil
}