pretty print JSON Rails -




i'm new rails. i'm trying pretty print json output.

there no view files involved.

a method generates json output, , controller renders view of json.

i've added json.pretty_generate inside method as:

json.pretty_generate({"files" => list_files}.to_json) 

but didn't work. i've added in render in controller, such following:

method:

def list_files_json   list_files = google_files.map |o|     {title: o.title, id: o.id, size: o.size, created_at: o.created_time}   end   {"files" => list_files}.to_json end 

controller:

def show     google_list = discoursedownloadfromdrive::drivedownloader.new(nil).list_files_json      respond_to |format|       format.json {render json: json.pretty_generate(google_list)}       format.html {render html: google_list}     end   end 

i've checked other threads related, , tried imitate solution (unsuccessfully). missing?

instead of {"files" => list_files}.to_json return {"files" => list_files} try this.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -