
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
grunt-concat-json
Advanced tools
Grunt Task for Merging Multiple JSON Files
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-concat-json --save
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-concat-json');
Type: String
|Array
The path to the source JSON files or collection of individual files. For instance: "src/**/*.{json,js}"
, which will concatenate all JSON and JS files in the src
folder.
Type: String
The path to the output concatenated JSON file.
Type: String
Default: null
The root folder to source files from. This will exclude this folder and it's parents from nested layer representation in the output JSON file. If cwd
is set, then the root folder does not need to be specified as part of the src
.
Type: String
Default: []
The token to use as suffix to a folder name to signify the contents should be rendered as an Array of items and not a Object.
Type: function
Default: null
The replacer argument for JSON.stringify()
(second argument).
Type: String
Default: ""
The space argument for JSON.stringify()
(third argument).
Run this task with the grunt concat-json
command.
Task targets, files and options may be specified according to the Grunt Configuring tasks guide.
Assuming we have the following types of source JSON files:
src/foo/foo-en.json
:
{
"foo": {
"title": "The Foo",
"name": "A wonderful component"
}
}
src/bar/bar-en.json
:
{
"bar": {
"title": "The Bar",
"name": "An even more wonderful component"
}
}
Will generate the following destination JSON file:
{
"foo": {
"title": "The Foo",
"name": "A wonderful component"
},
"bar": {
"title": "The Bar",
"name": "An even more wonderful component"
}
}
If a .json file and a folder share the same name, they will be merged into one object when the JSON is concatenated. Assuming we have the following source JSON files:
src/foo.json
:
{
"default": {
"title": "The Foo",
"name": "A wonderful component"
}
}
src/foo/bar.json
:
{
"title": "The Bar",
"name": "An even more wonderful component"
}
Will generate the following destination JSON file:
{
"foo": {
"default": {
"title": "The Foo",
"name": "A wonderful component"
},
"bar": {
"title": "The Bar",
"name": "An even more wonderful component"
}
}
}
The contents of a folder can be grouped together as an array. The folder must end in a unique symbol, the default is '[]'; For the files
src/foo[]/foo1.json
:src/foo[]/foo2.json
:src/foo[]/foo3.json
:{
"foo": [
{
//contents of foo1.json...
},
{
//contents of foo2.json...
},
{
//contents of foo3.json...
},
]
}
The javascript file can take two forms - either an object literal, or the contents of a function where your return value becomes the JSON object for the file.
{
//if the first character is the first character of an object literal, then it is evaluated that
//way. This means that if your JSON as JS is set up that way, you can't have whitespace or
//a comment as the first text
TWO_PI: Math.PI * 2,
foo: "bar"
}
//other javacript is wrapped within a function, allowing you to create your object however you like
var rtn;
for(var i = 100; i > 50; --i)
rtn.push(i);
//The return value here is the final result, which saves us from having to make our array
//of integer values form 100 to 51 by hand.
return rtn;
Note, that the .json files in an array folder do not retain their file names as keys, since they are now array index items.
grunt.initConfig({
"concat-json": {
"en": {
src: [ "src/**/*-en.json" ],
dest: "www/en.json"
},
"de": {
src: [ "src/**/*-de.json" ],
dest: "www/de.json"
}
}
});
grunt.initConfig({
"concat-json": {
"i18n": {
files: {
"www/en.json": [ "src/**/*-en.json" ],
"www/de.json": [ "src/**/*-de.json" ]
}
}
}
});
FAQs
Grunt Task for Merging Multiple JSON Files
We found that grunt-concat-json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.