knife-backup icon indicating copy to clipboard operation
knife-backup copied to clipboard

Fix pretty JSON generation

Open QueerCodingGirl opened this issue 9 years ago • 10 comments

see: http://stackoverflow.com/questions/2567670/ruby-json-pretty-generate-is-pretty-unpretty It would be really nice for reading and editing the backups before restoring them.

QueerCodingGirl avatar Jan 26 '16 15:01 QueerCodingGirl

Which version are you using and which data are you referring to?

pmoosh avatar Jan 29 '16 17:01 pmoosh

I am using version v0.0.11 and i am referring to the minified JSON, for example in the roles backup files.

QueerCodingGirl avatar Jan 29 '16 18:01 QueerCodingGirl

@DarkGigaByte - thx, by any chance did you look into other files that you backed up? Will look into it.

pmoosh avatar Jan 29 '16 18:01 pmoosh

Yeah, i did. The data bags are fine and pretty formatted. The other categories are all not/unpretty formatted.

QueerCodingGirl avatar Jan 29 '16 19:01 QueerCodingGirl

@DarkGigaByte Send me an example if can. Mine look fine...

pmoosh avatar Jan 29 '16 20:01 pmoosh

Example of unpretty environment "development" exported on Linux Mint: {"name":"development","description":"development","cookbook_versions":{"foobar_cookbook":"= 0.1.0"},"json_class":"Chef::Environment","chef_type":"environment","default_attributes":{},"override_attributes":{}}

How it should look pretty formatted: http://pastebin.com/Ju7m7FUt

QueerCodingGirl avatar Jan 29 '16 20:01 QueerCodingGirl

it was prettified in 0.0.8, but something changed between 0.0.8-0.0.10

please add prettifying back, as i'm commiting the backup versions to git, it would be easier to see changes if prettified.

EDIT: i think the real change was with underlying ruby upgrade 1.9 -> 2.4

glensc avatar Dec 21 '18 11:12 glensc

i don't get it. if i read and invoke JSON.pretty_generate, it works fine:

file_name = 'nodes/example.json'
data = File.read(file_name)
some_data = JSON.parse(data)
encoded = JSON.pretty_generate(some_data)
yourfile = '/tmp/out.json'
File.open(yourfile, 'w') { |file| file.write(encoded) }

and the code uses same method: https://github.com/mdxp/knife-backup/blob/v0.0.12/lib/chef/knife/backup_export.rb#L127

glensc avatar Dec 21 '18 11:12 glensc

i'm even more puzzled, i updated 0.0.10 to 0.0.12 and the output is prettified.

versions (mostly note to myself):

$ rpm -q ruby knife-backup ruby-json
ruby-2.4.4-12.x86_64
knife-backup-0.0.12-1.noarch
ruby-json-2.0.4-2.4.4.12.x86_64

glensc avatar Dec 21 '18 12:12 glensc

so, imho it can be closed. as output is prettified

glensc avatar Dec 22 '18 14:12 glensc