Coder Social home page Coder Social logo

grunt-properties-to-json's Introduction

THIS PROJECT IS NO LONGER MAINTAINED

grunt-properties-to-json

Build Status dependency Status devDependency Status

A grunt plugin for converting java property files to JSON files.

Getting Started

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-properties-to-json --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-properties-to-json');

Usage

With the following config, each .properties file in src will be converted to json and will be saved as a .json file in the same directory as the property file.

grunt.initConfig({
    propertiesToJSON: {
        main: {
            src: ['path/to/properties/files', 'another/path/to/properties/files']
        }
    }
});

It is also possible to define a destination folder for the generated json files:

grunt.initConfig({
    propertiesToJSON: {
        main: {
            src: ['path/to/properties/files', 'another/path/to/properties/files'],
            dest: 'tmp'
        }
    }
});

Split keys by a separator

You can split keys in the property files by using the splitKeysBy option (a string or regular expression). With this option the keys in the property files will be splitted by the given string or regular expression and used as nested keys in the JSON output.

grunt.initConfig({
    propertiesToJSON: {
        main: {
            src: ['path/to/properties/files', 'another/path/to/properties/files'],
            dest: 'tmp',
            options: {
                splitKeysBy: '.'
            }
        }
    }
});

Include and/or exclude keys

You can explicitly include and/or exclude namespaces, effectively whitelisting or blacklisting. For each option, provide a string, regular expression or an array of strings and regular expressions. If both options are used, exclusions are applied first, then inclusions. If you combine this option with splitKeysBy you can include and/or exclude nested keys by respectively setting the deepInclude or deepExclude option to true.

grunt.initConfig({
    propertiesToJSON: {
        main: {
            src: ['path/to/properties/files', 'another/path/to/properties/files'],
            dest: 'tmp',
            options: {
                splitKeysBy: '.',
                exclude: ['message', /label$/],
                deepExclude: true
            }
        }
    }
});

Merge multiple property files to one JSON file

If you want multiple property files to be merged to one JSON file, you can set the merge option to true. The destination should be a file in which the merged JSON output will be written. You can combine this option with the options mentioned above (the merge will be applied as last operation, so splitted keys will also be merged).

grunt.initConfig({
    propertiesToJSON: {
        main: {
            src: ['path/to/properties/files', 'another/path/to/properties/files'],
            dest: 'tmp.json',
            options: {
                merge: true
            }
        }
    }
});

License

This project is released under the MIT license.

grunt-properties-to-json's People

Contributors

jcbvm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

grunt-properties-to-json's Issues

Accents encoding

I have a simple file properties:

test = accent éèçéçàç

which is generated into a json file, but the accents are lost as if they were bad encoded
{"test":"accent �������"}

Note : the source file is ISO-8859-1 but the characters are correct in this format

Warning: Arguments to path.join must be strings

I ran into this problem, tried some solutions from SO bu with no luck.

 ❯ grunt propertiesToJSON --force                                                                                                                                    
Running "propertiesToJSON:main" (propertiesToJSON) task
Warning: Arguments to path.join must be strings Used --force, continuing.

Done, but with warnings.

Here's my gruntfile:

module.exports = function(grunt) {
  grunt.initConfig({
    propertiesToJSON: {
      main: {
        src: ['conf/xxx.properties']
      }
    }
  });

  grunt.loadNpmTasks('grunt-properties-to-json');
};

Thank you!

If use 'splitKeysBy' option, error occurred.

Hi. Thank you for this project.
Anyway, I'm using this library but if I use 'splitKeysBy' option, error is being occurred.

[INFO] Running "propertiesToJSON:main" (propertiesToJSON) task
[INFO] Warning: Cannot assign to read only property 'location' of Search conditions� Use --force to continue.

I added just splitKeysBy: '.' and I don't know what property has problem.
Please check this.
Thank you.

Unescape special chars

Special chars # ! : and = which are escaped with a backslash should be unescaped before written to json.

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.