# json-structure-diff

> Compare JSON objects for structure equality, despite the actual content

Latest version **0.0.2** (published 2015-10-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install json-structure-diff
pnpm add json-structure-diff
yarn add json-structure-diff
bun add json-structure-diff
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2015-10-18 |
| First published | 2015-10-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Filipe Garcia |
| Maintainers | fgarci03 |

## Links

- npm: https://www.npmjs.com/package/json-structure-diff
- Repository: git@github.com:fgarci03/json-structure-diff
- Homepage: https://github.com/fgarci03/json-structure-diff
- Issues: https://github.com/fgarci03/json-structure-diff/issues
- npm.io page: https://npm.io/package/json-structure-diff

## Recent versions

- 0.0.2 (latest) — 2015-10-18
- 0.0.1 — 2015-10-18
- 0.0.0 — 2015-10-18

## README

# json-structure-diff

Compare JSON objects for structure equality, despite the actual content

## Installation

```shell
npm install --save json-structure-diff
```

or

```shell
bower install --save json-structure-diff
```

## Usage

NPM:
```js
var compare = require('json-structure-diff').compareJSONObjects;

var obj1 = {
  parent: 'nameOfObject',
  content: {
    whatever: 'you',
    want: {
      here: '!'
    }
  }
};

var obj2 = {
  parent: 'nameOfComparedObject',
  content: {
    whatever: 'you',
    want: {
      here: {
        is: 'cool',
        right: '?'
      }
    }
  }
};

var objectsToCompare = [obj1, obj2];

var errors = compare(objectsToCompare, options);
```

BOWER:
```js
<script src="json-structure-diff/index.js"></script>
<script>
  jsonStructureDiff.compareJSONObjects([oj1, obj2], options);
</script>
```

This function accepts an array of objects to be compared, and returns a list of errors if they exist, or null if they don't.
It checks strictly for JSON structure without looking at the contents. It does check if the ```typeof``` variable matches!


The objects need to have 2 properties:
+ **parent**: The name of the object, to use on the error list;
+ **content**: the actual content of the object to compare.


Optionally, you can pass an 'options' object with a ```humanReadable``` boolean property. If true, the return value of the method
is an array of strings (```['nameOfObject > want.here is string and nameOfComparedObject > want.here is object']```), else it's
an array of objects:
```js
[
  {
    parent: 'nameOfObject.want.here',
    comparedParent: 'nameOfComparedObject.want.here',
    typeOfParent: 'string',
    typeOfComparedParent: 'object'
  }
]
```
Default value is false.

## Credits
[Filipe Garcia](https://github.com/fgarci03/)

## License

ISC

## TODO
+ Handle circular references without throwing error - [https://github.com/douglascrockford/JSON-js/blob/master/cycle.js](https://github.com/douglascrockford/JSON-js/blob/master/cycle.js);
+ TESTS!!;
+ Handle ALL types of javascript variables (stop using ```typeof```);

---
_Source: https://npm.io/package/json-structure-diff · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
