Test Json File before converging resource?

Hi everyone,

I have an instance in a cookbook where developers can freely add json files to a directory. If the cookbook_file resource converges, it notifies an execute resource to make an api call and send that json to a remote location.

Is there a chef tool that I can use to test that json file and verify that it is indeed valid json?? If I could make the api call wait on that check before pushing the file, it could save us an enormous amount of headaches caused from allowing us to post json files in which devs left in an extra comma or something.

Would be an epic tool if it exists!

thanks!

There is no special tool but I think you could use pure ruby to accomplish this. For example:

irb(main):001:0> require "json"
=> true
irb(main):002:0> JSON.parse("blah")
JSON::ParserError: 743: unexpected token at 'blah'
        from C:/Users/MattWrock/AppData/Local/chefdk/gem/ruby/2.3.0/gems/json-2.0.2/lib/json/common.rb:156:in `parse'
        from C:/Users/MattWrock/AppData/Local/chefdk/gem/ruby/2.3.0/gems/json-2.0.2/lib/json/common.rb:156:in `parse'
        from (irb):2
        from C:/opscode/chefdk/embedded/bin/irb.cmd:19:in `<main>'

I would recommend using Chef's FFI YAJL library, as it's engineered to have better error messages for humans to read.