<commit_before># karma-json2js-preprocessor

> Preprocessor for converting JSON files into JS strings.

## Installation

The easiest way is to keep `karma-json2js-preprocessor` as a devDependency in your `package.json`.
```json
{
  "devDependencies": {
    "karma": "~0.10",
    "karma-json2js-preprocessor": "~0.1"
  }
}
```

You can simple do it by:
```bash
npm install karma-json2js-preprocessor --save-dev
```

## Configuration
Following code shows the default configuration...
```js
// karma.conf.js
module.exports = function(config) {
  config.set({
    preprocessors: {
      '**/*.json': ['json2js']
    },

    files: [
      '*.js',
      '*.json'
    ]
  });
};
```

## How does it work ?

This preprocessor converts JSON files into JS strings and publishes them in the global `window.__json__`, so that you can use these for testing mock json requests and responses.

For instance this `example.json`...
```js
{
    "name": "foo",
    "friends": [
        {
            "name": "bar"
        }
    ]
}
```
... will be served as `example.json.js`:
```js
window.__json__ = window.__json__ || {};
window.__json__['example.json'] = '{"name":"foo","friends":[{"name":"bar"}]}';
```

See the [end2end test](https://github.com/kenglxn/karma-json2js-preprocessor/tree/master/e2e-test) for a complete example.
<commit_msg>updated readme with some info about why not to use this, and what to do instead<commit_after># karma-json2js-preprocessor

a carbon copy of karma-html2js-preprocessor. Only difference is the name, and the fact that it stores files in window.__json__ instead of __html__

If you need this just use html2js instead:

```js
module.exports = function (config) {
  config.set({
    frameworks: ["jasmine"],
    files: [
        '**/*.js',
        '**/*.html',
        '**/*.json',
        '**/*.spec.js'
    ],
    plugins: [
        'karma-html2js-preprocessor'
    ]
    preprocessors: {
        '**/*.html': ['html2js'],
        '**/*.json': ['html2js']
    }
  });
};
```

Then do what you need with the json or html:

```js
var exampleJson = __html__['example.json'];
var jsonObj = JSON.parse(exampleJson);
var exampleHtml = __html__['example.html'];
document.body.innerHTML = exampleHtml;
```

### Related:

* https://github.com/karma-runner/karma/issues/858
* http://stackoverflow.com/questions/20690005/why-is-karma-refusing-to-serve-my-json-fixture-which-id-like-to-use-in-my-jasm

{'fraction_non_alphanumeric': 0.16680497925311202, 'fraction_numerical': 0.012448132780082987, 'mean_word_length': 3.2076788830715532, 'pattern_counts': {'":': 9, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2291089', 'n_tokens_mistral': 840, 'n_tokens_neox': 800, 'n_words': 210}