This is embarrassing since I'm just learning, but in the interest of 
getting feedback and improving my Julia coding skills, here is what I did:

function df2json(df::DataFrame)

nrow,ncol = size(df)

io = IOBuffer();
write(io,"[\n")
for irow = 1:nrow
  irow == nrow ? eor = "" : eor = ","
  write(io,"{")
  for icol = 1:ncol
    icol == ncol ? eoe = "" : eoe = ","
    sym = names(df)[icol]
    name = string(sym)
    if isa(value,Number)
      write(io,"\""*name*"\":"*string(df[irow,sym])*eoe)
    else
      write(io,"\""*name*"\":\""*df[irow,sym]*"\""*eoe)
    end
  end
  write(io,"}"*eor*"\n")
end
write(io,"]\n")

json = takebuf_string(io)
close(io)
json
end


Any thoughts/suggestions? Thank you.

Reply via email to