Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant merge an json Array #11

Closed
CoHyper opened this issue Feb 25, 2016 · 3 comments
Closed

Cant merge an json Array #11

CoHyper opened this issue Feb 25, 2016 · 3 comments

Comments

@CoHyper
Copy link

CoHyper commented Feb 25, 2016

  • Actual behaviour
    {"modules": [{"id": 2}]}
  • Expected behaviour
    {"modules": [{"id": 1}, {"id": 2}]}
  • Reproduce
    file1.json
    {"modules": [{"id": 1}]}
    file2.json
    {"modules": [{"id": 2}]}
var
    gulp = require('gulp'),
    jsonMinify = require('gulp-jsonminify'),
    mergeJSON = require('gulp-merge-json'),
    rename = require('gulp-rename');

return gulp.src('config/**/*.json')
    .pipe(merge('manni.json'))
    .pipe(gulp.dest(this.opts.DIR_BUILD_DIST));

/*
        .pipe(jsonMinify())
        .pipe(rename('manni.min.json'))
        .pipe(gulp.dest(this.opts.DIR_BUILD_DIST))
        .pipe(gulp.dest(this.opts.DIR_BUILD_APP_WWW));
*/
@joshswan
Copy link
Owner

Unfortunately this is currently expected behavior when the array contains objects. The actual object merging is handled by deepmerge, which concats simple array values but merges objects. There are a couple of open PRs (e.g. TehShrike/deepmerge#21) that seem like they'll solve this issue, but there hasn't been much movement lately. Once they're merged or an alternative is found, I'd be happy to accept a PR to expose a setting for this behavior.

@CoHyper
Copy link
Author

CoHyper commented Mar 10, 2016

my solution

@joshswan
Copy link
Owner

I didn't think of using lodash's merge. Version 0.4.0 that was just published to npm has a "concatArrays" option that should do what you're looking for now. I will update the documentation soon, but if you were to replace merge('manni.json') with merge('manni.json', false, false, false, false, true) or merge({ filename: 'manni.json', concatArrays: true }), you should get the desired result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants