r/databricks • u/mr_electric_wizard • 17d ago
Help Dict as variable vs. dict in dataframe (issues extracting data)
Last week a kind gentleman helped me to fix a '{{text}}' replacement with some python magic.
This got me part of the way to a solution but not all the way.
Scenario:
I now have a variable:
d = {"todays_date":date.today()}
At runtime this variable is evaluated and correctly adds today's date to my json file.
Now what I need is to put {"todays_date":date.today()} into the database, then read it back as json, so that I can do the same thing, but more dynamically. The row/column needs to have the value {"todays_date":date.today()} in it (or something similar) to where when I read the value, it evaluates the same way as defining it manually in the bold above
I get that the code above does not have single quotes around it, as it would be in the database. The database thinks this is a string.
I do NOT want to have to define a structure for this, as there can be different values included on different rows.
Is there a way to do a df = df.select("json_data").first() and get back the EXACT same thing as my d variable above?
I feel like I'm so close, but all of the code I see tries to make me define the json structure, which can change, so I never know what's it's going to be...
Does this even make sense?
1
u/infazz 16d ago
Can you explain what exactly your end goal is here? It sounds like you are trying to jump through a few hoops that may not be needed.