Setting values in arrays in config.cson programmatically?


If the config.cson looks like

and I want to change only the value of ‘i’, how can I do that from a script with atom.config.set()?
Because of the array structure [{…}], it becomes tricky at some point:
atom.config.set(‘a.b.???’, newValue)


Atom’s configuration API wasn’t designed for structures like you’re showing here. So underneath a.b you’re on your own for maintaining it. None of this will show up very well in the Settings View either.


By getting the whole array, then changing the value, then putting the whole array back in. It will work fine with CSON.

module.exports = myPackage =

   activate: ->
      logI()  # -> 17
      setI 19
      logI()  # -> 19

         type: 'array'
         default: [
            {h: {j:15}},
            {g: {i: 17}}
         description: 'some objects'

   logI : ->
      console.log atom.config.get('my-package.myObjects')[1]['g']['i']

   setI : (value) ->
      objArray = atom.config.get('my-package.myObjects')
      objArray[1]['g']['i'] = value
      atom.config.set('my-package.myObjects', objArray)