grunt-json-to-object v0.1.2
grunt-json-to-object
Reads pure JSON data from a file and creates a Javascript file holding an object with the data
Getting Started
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-json-to-object --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-json-to-object');
The "json_to_object" task
Overview
In your project's Gruntfile, add a section named json_to_object
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
json_to_object: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
});
Options
options.varname
Type: String
Default value: jsonObj
A string value that is used as the variable name for the resulting Javascript object.
Usage Examples
Default Options
In this example, the default options are used to create a Javascript file with an object jsonObj
exposed to the global namespace.
grunt.initConfig({
json_to_object: {
options: {},
files: {
'dest/json-data.js': ['src/json-data-1.json', 'src/json-data-2.json'],
},
},
});
Custom Options
In this example, custom options are used to create a Javascript file with an object fooObj
exposed to the global namespace.
grunt.initConfig({
json_to_object: {
options: {
varname: 'fooObj'
},
files: {
'dest/json-data.js': ['src/json-data-1.json', 'src/json-data-2.json'],
},
},
});
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
0.1.1 Removed IntelliJ files, updated .gitignore and README.md 0.1.2 Refactored handling of multiple input files