{"action":"created","issue":{"url":"https://api.github.com/repos/chef/chef/issues/4169","labels_url":"https://api.github.com/repos/chef/chef/issues/4169/labels{/name}","comments_url":"https://api.github.com/repos/chef/chef/issues/4169/comments","events_url":"https://api.github.com/repos/chef/chef/issues/4169/events","html_url":"https://github.com/chef/chef/issues/4169","id":116949726,"number":4169,"title":"Chef can't parse JSON roles without unexpected error","user":{"login":"skipperguy12","id":1821399,"avatar_url":"https://avatars.githubusercontent.com/u/1821399?v=3","gravatar_id":"","url":"https://api.github.com/users/skipperguy12","html_url":"https://github.com/skipperguy12","followers_url":"https://api.github.com/users/skipperguy12/followers","following_url":"https://api.github.com/users/skipperguy12/following{/other_user}","gists_url":"https://api.github.com/users/skipperguy12/gists{/gist_id}","starred_url":"https://api.github.com/users/skipperguy12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skipperguy12/subscriptions","organizations_url":"https://api.github.com/users/skipperguy12/orgs","repos_url":"https://api.github.com/users/skipperguy12/repos","events_url":"https://api.github.com/users/skipperguy12/events{/privacy}","received_events_url":"https://api.github.com/users/skipperguy12/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-14T20:08:41Z","updated_at":"2015-11-16T19:32:27Z","closed_at":"2015-11-16T19:32:27Z","body":"### Version:\r\nVagrant is using 12.5.1\r\n\r\n### Environment:\r\nI'm on Mac OSX Yosemite, Vagrant is using ubuntu/trusty64\r\n\r\nMy Vagrantfile:\r\n```\r\nVAGRANTFILE_API_VERSION = \"2\"\r\n\r\nVagrant.configure(VAGRANTFILE_API_VERSION) do |config|\r\n  # Setup resource requirements\r\n  config.vm.provider \"virtualbox\" do |v|\r\n    v.memory = 1024\r\n    v.cpus = 2\r\n  end\r\n\r\n  config.vm.box = \"ubuntu/trusty64\"\r\n  #config.berkshelf.enabled = true\r\n  config.librarian_chef.cheffile_dir = \"../chef\"\r\n\r\n  # This should match the version specified in your\r\n  # Gemfile\r\n  config.omnibus.chef_version = :latest\r\n\r\n  # Assumes that the Vagrantfile is in the root of our\r\n  # Chef repository.\r\n  root_dir = File.dirname(File.expand_path(__FILE__))\r\n\r\n  # Assumes that the node definitions are in the nodes\r\n  # subfolder\r\n  nodes = Dir[File.join(root_dir,'nodes','*.json')]\r\n\r\n  # Iterate over each of the JSON files\r\n  nodes.each do |file|\r\n    puts \"parsing #{file}\"\r\n    node_json = JSON.parse(File.read(file))\r\n\r\n    # Only process the node if it has a vagrant section\r\n    if(node_json[\"vagrant\"])\r\n\r\n      # Allow us to remove certain items from the run_list if we're\r\n      # using vagrant. Useful for things like networking configuration\r\n      # which may not apply.\r\n      if exclusions = node_json[\"vagrant\"][\"exclusions\"]\r\n        exclusions.each do |exclusion|\r\n          if node_json[\"run_list\"].delete(exclusion)\r\n            puts \"removed #{exclusion} from the run list\"\r\n          end\r\n        end\r\n      end\r\n\r\n      vagrant_name = node_json[\"vagrant\"][\"name\"] \r\n      vagrant_ip = node_json[\"vagrant\"][\"ip\"]\r\n\r\n      config.vm.define vagrant_name do |vagrant|\r\n        vagrant.vm.hostname = vagrant_name\r\n\r\n        # Only use private networking if we specified an\r\n        # IP. Otherwise fallback to DHCP\r\n        if vagrant_ip\r\n          vagrant.vm.network :private_network, ip: vagrant_ip\r\n        end\r\n\r\n        vagrant.vm.provision \"chef_solo\" do |chef|\r\n\r\n          # Use berks-cookbooks not cookbooks and remember\r\n          # to explicitly vendor berkshelf cookbooks\r\n          chef.cookbooks_path = [\"site-cookbooks\"]\r\n          chef.data_bags_path = \"data_bags\"\r\n          chef.roles_path = \"roles\"\r\n\r\n          # Instead of using add_recipe and add_role, just\r\n          # assign the node definition json, this will take\r\n          # care of populating the run_list.\r\n          chef.json = node_json\r\n        end\r\n      end\r\n    end\r\n  end\r\nend\r\n```\r\n\r\n### Scenario:\r\nI want to provision a Vagrant system to be ready for rails using a modified files from http://www.talkingquickly.co.uk/2014/08/auto-generate-vagrant-machines-from-chef-node-definitions\r\n\r\n### Steps to Reproduce:\r\nIn a Chef repo with a couple of basic Roles (I was using https://github.com/TalkingQuickly/rails-server-template but slightly modified to fit my needs, namely I didn't have any need for monit, postgresql, or mysql, so anything related to those are removed).\r\n\r\nI did `vagrant init`, pasted my Vagrant file which is mentioned above, then ran `vagrant up`.\r\n\r\n### Expected Result:\r\nChef should run the run list successfully.\r\n\r\n### Actual Result:\r\n```\r\n==> vagrant: ================================================================================\r\n==> vagrant: Error expanding the run_list:\r\n==> vagrant: ================================================================================\r\n==> vagrant: \r\n==> vagrant: Unexpected Error:\r\n==> vagrant: -----------------\r\n==> vagrant: Chef::Exceptions::JSON::ParseError: parse error: trailing garbage\r\n==> vagrant:           in\" : \"yes\"       }     }   },   \"json_class\": \"Chef::Role\",\r\n==> vagrant:                      (right here) ------^\r\n==> vagrant: \r\n==> vagrant: \r\n==> vagrant: [2015-11-14T19:54:28+00:00] ERROR: Running exception handlers\r\n==> vagrant: [2015-11-14T19:54:28+00:00] ERROR: Exception handlers complete\r\n==> vagrant: [2015-11-14T19:54:28+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out\r\n==> vagrant: [2015-11-14T19:54:28+00:00] ERROR: parse error: trailing garbage\r\n==> vagrant:           in\" : \"yes\"       }     }   },   \"json_class\": \"Chef::Role\",\r\n==> vagrant:                      (right here) ------^\r\n==> vagrant: [2015-11-14T19:54:28+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)\r\nChef never successfully completed! Any errors should be visible in the\r\noutput above. Please fix your recipes so that they properly complete.\r\n```\r\n\r\nI'm new to both Chef and Rails, so I do not have a clue why this doesn't work. According to a few SO posts, ignoring trailing garbage  (not sure what that means) is part of another JSON library?\r\n"},"comment":{"url":"https://api.github.com/repos/chef/chef/issues/comments/157145072","html_url":"https://github.com/chef/chef/issues/4169#issuecomment-157145072","issue_url":"https://api.github.com/repos/chef/chef/issues/4169","id":157145072,"user":{"login":"danielsdeleo","id":37162,"avatar_url":"https://avatars.githubusercontent.com/u/37162?v=3","gravatar_id":"","url":"https://api.github.com/users/danielsdeleo","html_url":"https://github.com/danielsdeleo","followers_url":"https://api.github.com/users/danielsdeleo/followers","following_url":"https://api.github.com/users/danielsdeleo/following{/other_user}","gists_url":"https://api.github.com/users/danielsdeleo/gists{/gist_id}","starred_url":"https://api.github.com/users/danielsdeleo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielsdeleo/subscriptions","organizations_url":"https://api.github.com/users/danielsdeleo/orgs","repos_url":"https://api.github.com/users/danielsdeleo/repos","events_url":"https://api.github.com/users/danielsdeleo/events{/privacy}","received_events_url":"https://api.github.com/users/danielsdeleo/received_events","type":"User","site_admin":false},"created_at":"2015-11-16T19:32:27Z","updated_at":"2015-11-16T19:32:27Z","body":"You probably have an extra `}` in your JSON. For example, I can trigger this error with:\r\n\r\n```json\r\n { }, \"foo\": \"bar\" \r\n```\r\n\r\nAttempting to parse gives:\r\n\r\n```\r\nFFI_Yajl::Parser.parse s\r\nFFI_Yajl::ParseError: parse error: trailing garbage\r\n                                    { }, \"foo\": \"bar\" \r\n                     (right here) ------^\r\n```\r\n\r\nAnd yes, Chef uses our own JSON library: https://github.com/chef/ffi-yajl because yajl is the only parser available that produces somewhat decent error messages."}}