Q:

copy JSON files from one dir to another

In my web project I have the following directory  structure
|- target
|- foo
|- bar
|- baz

I'm trying to write a Grunt task that will copy all JSON files into the target directory from the directory whose name matches a parameter provided to the build
grunt.registerTask('flavor', function(srcDir) {
  var from = './' + srcDir + '/*.json';
  var dest = './target/';

  grunt.file.expand(from).forEach(function(src) {
    grunt.file.copy(src, dest);
  });   
});

But when I call this with 
grunt flavor:foo

I get an error

Warning: Unable to write "./target/" file (Error code: EISDIR). Use --force to continue.

A:

As @DanielApt mentioned, you should just use grunt-contrib-copy. To build on his answer regarding on your comment about build-parameters, you can get them to the task via grunt-option.
Way one: running different target 
 grunt.initConfig({
    copy: {
        foo: {
            files: [
                {
                    'expand': 'true',
                    'cwd': 'foo/',
                    'src': [**],
                    'dest': 'dist/en'
                }
             ]
          },
        bar: {
            files: [/**/]
        },
        baz: {
            files: [/**/]
        }
    }
});

var target = grunt.option("target") || "foo";

grunt.registerTask("default", ["copy:" + target]);

// run with grunt --target=foo

Way 2: Arbituary folder with templating:
var target = grunt.option("target") || "foo";

grunt.initConfig({
    target: target,
    copy: {
        default_target: {
            files: [
                {
                    'expand': 'true',
                    'cwd': '<%= target %>/',
                    'src': [**],
                    'dest': 'dist/en'
                }
             ]
        },
    }
});

grunt.registerTask("default", ["copy"]);

// run with grunt --target=anyfolderhere

