I have data like so:
{"key": {"name":"hi", "size":10}}
"key" is a dynamic value. It isn't fixed. I can access name
and size
using this JSON Path:
*.name
*.size
How can I get the value of "key" itself with JSON Path? *
gives me the entire row of data, and both $
and @
give me "no element found" in my parser.
I'm trying to do this in Pentaho with a JSON Input step.
According to the modified Backus-Naur-Form on the right side pane of http://json.org/ the root element of a JSON data structure can be any of these seven types/values: Object Array String Number true false null.
JsonPath expressions always refer to a JSON structure in the same way as XPath expression are used in combination with an XML document. The "root member object" in JsonPath is always referred to as $ regardless if it is an object or array. JsonPath expressions can use the dot–notation. $.store.book[0].title.
You use a JSONPath expression to traverse the path to an element in the JSON structure. You start at the root node or element, represented by $, and reach the required element in the JSON structure to extract data from it. You can use either the dot-notation or the bracket-notation to form the expressions.
$.*
will give you all elements of parent object, in your example you will get something like
[
{
"name":"hi",
"size":10
}
]
according to: http://jsonpath.curiousconcept.com/
This is not possible to do with the Pentaho JSON Input step, as this uses JSONPath as you say. You need to do it another way. For example with the Modified Java Script Value
:
var obj = JSON.parse(json);
var keys = Object.keys(obj);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With