Code Monkey home page Code Monkey logo

grunt-json-minify's Introduction

grunt-json-minify

Build Status

Grunt JSON minification task that does not concatinate the output. For concatination use grunt-minjson.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-json-minify

Then add this line to your project's Gruntfile.js gruntfile:

grunt.loadNpmTasks('grunt-json-minify');

Usage

Set the files parameter to the directory you want to minify. The minification is inplace, so you want to copy the data to the destination before you minify.

Example:

'json-minify': {
  build: {
    files: 'build/**/*.json'
  }
}

Options

  • encoding(Default undefined) The encoding that should be used for reading and writing the json files.
  • skipOnError (Default false) Ignore files that produce a parse error while minification.

Internally this plugin uses the JSON.stringify and JSON.parse method for minification. You can configure this process by the following parameters:

  • reviver (Default undefined) If a function, prescribes how the value originally produced by parsing is transformed, before being returned.
  • replacer (Default undefined) A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string.
  • space (Default '') A String or Number object that's used to insert white space into the output JSON string for readability purposes. If this is a Number, it indicates the number of space characters to use as white space; this number is capped at 10 if it's larger than that. Values less than 1 indicate that no space should be used. If this is a String, the string (or the first 10 characters of the string, if it's longer than that) is used as white space. If this parameter is not provided (or is null), no white space is used.

For more informations see the JSON.parse and JSON.stringify documentation.

If you want to use your own minification algorithm you can overwrite the default behaviour by using the transform options:

'json-minify': {
  options: {
    transform: function (data, options) {
      return JSON5.stringify(JSON5.parse(data));
    }
  },
  build: {
    files: 'build/**/*.json'
  }
}

This example reconstructs the previous behavior before version 1.0.0. The data attribute is the json file content and the options are the current task options.

License

Copyright (c) 2016 werk85 Licensed under the MIT license.

grunt-json-minify's People

Contributors

dmadan86 avatar mmjmanders avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

grunt-json-minify's Issues

UTF-16 Files

I'm trying to minify a language file which is UTF-16 encoded and it's giving errors for ? mark characters since I believe it's trying to read the file as UTF-8?

Is there a way to fix this or specify it in the config options?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.