I want to extract the value (.68) from this string.
How would I go about doing this?
{"values":[{"source":"source_value","value":".68"},
{"source":"source.units","value":"%"},
{"source":"source_name","value":"Chemical"}]}
Currently, I have tried:
sub(".*:", "", df$value_as_string)
But I only get:
""Chemical"}]}"
2
Answers
Use the jsonStrings package to manipulate JSON strings:
Explanation:
"values", 0, "value"
is the path to".68"
. First the"values"
key, where we found an array, then0
, the first element of this array, then"value"
, the key of".68"
.The jsonlite package is another option.
Now
j$values
is a data frame. Note that the value "0.68" is type character, not numeric.