Hi everyone,
I’m currently trying to untangle a pretty messy multi-nested json file by flattening them out manually and curating them into a dataframe (mostly following the method described here: https://julia.school/julia/json/).
Some of the sub-nested elements are giving me some issues - I ended up with arrays like below, let’s say named ‘nest1_array’:
Dict{String, Any}("sub" => "K2")
Dict{String, Any}("sub" => "A5")
Dict{String, Any}("sub" => "G1")
Dict{String, Any}("sub" => "G1")
Dict{String, Any}("sub" => "B1")
nothing
Dict{String, Any}("sub" => "GD2")
nothing
nothing
nothing
Dict{String, Any}("sub" => "A6")
Dict{String, Any}("sub" => "C1")
Now my goal is do below to isolate ‘sub’ elements from above into its own array and push it into a manually curated dataframe, via:
clean_array=Any[]
for i in eachindex(nest1_array)
push!(clean_array, nest1_array[i]["sub"])
end
curated_df[!, :sub]=clean_array
Unfortunately, trying to isolate ‘sub’ entries from the nest1_array does not work, giving me below error message:
ERROR: MethodError: no method matching getindex(::Nothing, ::String)
Now, I can vaguely understand the error is because ‘nothing’ is its own data type, and indexing it along with the rest of the strings might be problematic (please do feel free to point out if this is wrong, or if there are better elaborations for the beginner!).
But what would be a solution to this issue? Is there a preexisting method or function that can be used to convert ‘::Nothing’ data rows into a text, like ‘N/A’?
So far only solution I found was to export the array to a text file and just use shell utilities + regex to clean the output, but I would far, far prefer a pure Julia solution. Especially since I have dozens more of these nested columns to go through…
As usual, any advice would be appreciated. Thank you!