logo
down
shadow

Ruby JSON.pretty_generate ... is pretty unpretty


Ruby JSON.pretty_generate ... is pretty unpretty

By : user3861523
Date : November 20 2020, 07:00 PM
I think the issue was by ths following , To generate pretty JSON output it appears that you're only missing a puts call.
The data:
code :


Share : facebook icon twitter icon
Rails: JSON.pretty_generate(obj) in the controller does not produce pretty output

Rails: JSON.pretty_generate(obj) in the controller does not produce pretty output


By : Onur
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , To get pretty output of JSON from an active record object you have to first request the object as JSON.
code :
record.as_json
render json: JSON.pretty_generate(record.as_json)
ruby json.pretty_generate output

ruby json.pretty_generate output


By : jkondos
Date : March 29 2020, 07:55 AM
it helps some times First change hosts to array, if you are not using hosts as Hash in other places.
code :
hosts = []
hosts << {name: host, mac: eth, ip: address}
file = File.new("new_computers.json", "w")
file.puts JSON.pretty_generate(hosts)
ruby JSON.pretty_generate() doesn't work

ruby JSON.pretty_generate() doesn't work


By : Misha Persiantsev
Date : March 29 2020, 07:55 AM
hop of those help? JSON.pretty_generate inserts whitespace into the returned string.
If your'e dumping the string into an HTML document, all whitespace (such as newlines) is ignored, and rendered as a single space. In order to preserve whitespace, you need add a white-space: pre CSS style, or wrap the content in a
 tag. 				
ruby JSON.pretty_generate(hash,opts) does not use opts

ruby JSON.pretty_generate(hash,opts) does not use opts


By : Nigel Hopkins
Date : March 29 2020, 07:55 AM
wish helps you Firsty, my references: , The keys to the options hash must be symbols.
How to do an unpretty print on pretty JSON file in shell >> serial string JSON >> ES _bulk?

How to do an unpretty print on pretty JSON file in shell >> serial string JSON >> ES _bulk?


By : gfdesign
Date : March 29 2020, 07:55 AM
around this issue You can try the great jq tool for parsing JSON in the shell. To de-pretty print with jq, you can use either method below:
Related Posts Related Posts :
  • updating a rails partial with AJAX
  • SWFUpload with rails
  • Cucumber Record ID
  • Using STI path with same controller
  • Convert a date string to a Unix timestamp
  • Which CouchDB API to use for Rails?
  • What is Restful Routing?
  • how to use variable name with image tag
  • Ruby on Rails: attr_accessor for submodels
  • Storing multiple checkbox values in database
  • STI and polymorphs
  • Get Mechanize to handle cookies from an arbitrary POST (to log into a website programmatically)
  • link_to not working in script/console
  • How to change color of HAML tags in NetBeans?
  • ruby super keyword
  • Ruby number_to_currency displays a totally wrong number!
  • Dynamic URL -> Controller mapping for routes in Rails
  • Building Admin Areas in Rails - General Questions
  • What's causing "NoMethodError: undefined method `include?' for nil:NilClass"
  • Invalid AuthenticityToken everywhere
  • Is reading xml simple in rails or converting it to hash will be simpler?
  • adding model validation errors in rescue
  • Set rails request timeout (execution expired)
  • Test (with RSpec) a controller outside of a Rails environment
  • How to implement "short" nested vanity urls in rails?
  • In Mechanize what is the cookiejar and how does it differ from cookies?
  • Ruby on Rails Drawbacks
  • Wrong root on image_tag, include_tags, etc
  • How does the proc in the caches_action if clause get execute
  • show array size with will_paginate
  • ordering a collection by an association's property
  • Override as_json or to_json model class name
  • How should I deploy a patch to a Passenger-based production Rails application without downtime?
  • Rails - asynchronous tasks, forked processes, best practices
  • Rails controller
  • Git + GitHub + Heroku
  • Ruby on Rails Report Generator
  • Ruby on Rails: Model.all.each vs find_by_sql("SELECT * FROM model").each?
  • Rails to_xml override
  • How to test declarative_authorization with rspec
  • Multiple domains on a single rails app
  • How to check user's role after login in Rails?
  • How can I request an image and return it as black and white in rails?
  • Ruby Summer of Code Project Ideas
  • How do I write user-specific configuration into a rails app?
  • background-fu pluggin unable to run ./script/generate background
  • Call named routes in CakePHP as the same way in Ruby on Rails
  • How to install system_timer gem on Windows 7
  • GET params in ruby-on-rails project - best practices?
  • Which persistent & lightweight queue messaging for cross domain (> 2) data exchange with rails integration?
  • converting Date object to TimeWithZone
  • Access current_user in model
  • Should I use helper method for this method?
  • How can I call a controller action from a rake task?
  • Using the submit button to link to another page in rails
  • Disabling model's after_find only when called from certain controllers
  • Uninitialized constant Item::Types
  • Rails custom TimeZone
  • Rails, handling multiple redirects
  • Create a thumbnail of a dwg in in a linux environment
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk