Replies: 1 comment
-
|
We have a similar problem, and can't seem to find any incantation to make it work in our case. @tahayk 's solution comes close, but in our case our JSON is not in a "flat" structure, e.g. CREATE TABLE default.json_test (tags JSON) ENGINE = Memory;
INSERT INTO default.json_test (tags) VALUES
('{"a":"b"}'),
('{"c":{"d":"e"},"f":{"g":"h"}}')
;I'm looking for a query that will output something like: The solutions in the description don't quite work here: SELECT
property_name,
JSONExtractString(toString(tags), 'String') AS value
FROM default.json_test
ARRAY JOIN JSONAllPaths(tags) AS property_name
-- Empty values
┌─property_name─┬─value─┐
1. │ a │ │
2. │ c.d │ │
3. │ f.g │ │
└───────────────┴───────┘
SELECT
a.1 AS path,
a.2 AS value
FROM default.json_test
ARRAY JOIN JSONExtractKeysAndValues(toString(tags), 'String') AS a
-- No "nesting"
┌─path─┬─value─────┐
1. │ a │ b │
2. │ c │ {"d":"e"} │
3. │ f │ {"g":"h"} │
└──────┴───────────┘I've also tried SELECT
path,
getSubcolumn(tags, path) AS value
FROM default.json_test
ARRAY JOIN JSONAllPaths(tags) AS path
Received exception from server (version 25.4.7):
Code: 44. DB::Exception: Received from localhost:9000. DB::Exception: The second argument of function getSubcolumn should be a constant string with the name of a subcolumn: In scope SELECT path, getSubcolumn(tags, path) AS value FROM default.json_test ARRAY JOIN JSONAllPaths(tags) AS path. (ILLEGAL_COLUMN)I feel like I must be missing an obvious solution here but I can't seem to find any way to get this to work with nested JSON. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I'm trying to extract all the paths of a json column with its values, so far, I managed to find a solution by transforming the json column to a string in order to extract the value, and I want to know if there is a better way to do it without using
toString?You can use the following queries:
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions