Shane_IL Shane_IL - 1 year ago 65
JSON Question

Can I use grunt to set a property value in a json file?

Still learning the ropes of grunt and can't find a solution for this.
I have a config file, say config.json with some data.

When I run a specific grunt task I want to increment a value in the config.json file. I've been able to find a lot of information on how to read the file but nothing so far on changing a value.


Answer Source

you can use for replace string and save file

'string-replace': {
  dist: {
    files: {
      'dest/': 'src/**',
      'prod/': ['src/*.js', 'src/*.css'],
    options: {
      replacements: [{
        pattern: /\/(asdf|qwer)\//ig,
        replacement: '"$1"'
      }, {
        pattern: ',',
        replacement: ';'

with this grunt plugin u can substitute a regex pattern (or a simple string) with a replacement

the steps for make your final json are:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download