Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dingoeatingfuzz/chai-match-json

A Chai plugin for asserting JSON paths for an object
https://github.com/dingoeatingfuzz/chai-match-json

Last synced: about 2 months ago
JSON representation

A Chai plugin for asserting JSON paths for an object

Awesome Lists containing this project

README

        

## matchJSON, for Chai

[![Travis CI](https://travis-ci.org/DingoEatingFuzz/chai-match-json.svg?branch=master)](https://travis-ci.org/DingoEatingFuzz/chai-match-json)

A way to assert the structure of given JSON.

### Examples
It looks like this:

```js
var FIXTURE = {
name : 'foo',
value : 'bar',
additional : [ 'prop', 'er', 'ties' ]
};

expect(FIXTURE).to.matchJSON({
'$.name' : 'foo',
'$.value' : 'bar'
});
```

It uses [JSONPath](https://github.com/s3u/JSONPath) for validating paths. The JSONPath project is well documented
with how to specify path selectors (such as `$.children[3].prices[price<30]`).

### Build

```sh
$ browserify lib/match-json.js -o chai-match-json.js
```

### Test

```sh
$ npm install -g karma-cli
$ npm install
$ karma start
```