Exemple #1
0
			"number":  1234,
			"boolean": true,
			"map": map[string]interface{}{
				"k": "v",
				"n": 1,
			},
			"array": []interface{}{
				1,
				2,
				"fdsa",
			},
		}

		Context("tree.FindString()", func() {
			It("should fail if tree.Find() fails", func() {
				v, err := tree.FindString(data, "nonexistent")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(""))
			})

			It("should fail if path is not a string", func() {
				v, err := tree.FindString(data, "number")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(""))
			})

			It("should succeed if path exists and is string", func() {
				v, err := tree.FindString(data, "string")
				Ω(err).ShouldNot(HaveOccurred())
				Ω(v).Should(Equal("asdf"))
			})
Exemple #2
0
// Returns a string-typed value found in the JSON data
// returned in the response, at `path`
func (r *Response) StringVal(path string) (string, error) {
	return tree.FindString(r.Data, path)
}