MCPcopy
hub / github.com/cloudfoundry/cli / ParseJSONFromFileOrString

Function ParseJSONFromFileOrString

cf/util/json/json_parser.go:29–54  ·  view source on GitHub ↗
(fileOrJSON string)

Source from the content-addressed store, hash-verified

27}
28
29func ParseJSONFromFileOrString(fileOrJSON string) (map[string]interface{}, error) {
30 var jsonMap map[string]interface{}
31 var err error
32 var bytes []byte
33
34 if fileOrJSON == "" {
35 return nil, nil
36 }
37
38 if fileExists(fileOrJSON) {
39 bytes, err = readJSONFile(fileOrJSON)
40 if err != nil {
41 return nil, err
42 }
43 } else {
44 bytes = []byte(fileOrJSON)
45 }
46
47 jsonMap, err = parseJSON(bytes)
48
49 if err != nil {
50 return nil, err
51 }
52
53 return jsonMap, nil
54}
55
56func fileExists(path string) bool {
57 _, err := os.Stat(path)

Callers 5

ExecuteMethod · 0.92
ExecuteMethod · 0.92
ExecuteMethod · 0.92
ExecuteMethod · 0.92

Calls 3

fileExistsFunction · 0.85
readJSONFileFunction · 0.85
parseJSONFunction · 0.85

Tested by

no test coverage detected