parsing json string value column into dataframe structure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 09:22 PM
Hi All,
I have to read kafka payload which has value column with json string. But the format of the json is as below.
{ "data": [ { "p_al4": "N/A", "p_a5": "N/A", "p_ad": "OA003", "p_aName": "Abc", "p_aFlag": true ,....(dynamic)} ] }
In data key it can have dynamic number of key value pairs.
here "p_" is a column and respective value is given.
Please suggest how to create this payload into dataframe structure.
like below:
+-----+-----+-----+-------+------+------------------+
|p_al4 | p_a5 | p_ad | p_aName | p_aFlag|
+-----+-----+-----+-------+------+----------------+
|N/A | N/A | OU13| Admin | true |
+-----+-----+-----+-------+------+--------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 09:58 PM
Would you know the element in the Kafka event JSON ahead of the time or count the number of element each time and then generate the schema for such and pass it from_json to parse? https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.functions.from...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 10:30 PM
No I don't know element in JSON . so I can't define structure.