# jsonizer

> "Keep your JSON structures versioned"

Latest version **0.1.0** (published 2015-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsonizer
pnpm add jsonizer
yarn add jsonizer
bun add jsonizer
```

Provides the command `jsonize`.

## 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.1.0 |
| Published | 2015-12-21 |
| First published | 2015-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Elena Torro |
| Maintainers | elenatorro |
| Keywords | JSON structure, JSON version, versioning, JSON update |

## Links

- npm: https://www.npmjs.com/package/jsonizer
- npm.io page: https://npm.io/package/jsonizer

## Dependencies (5)

- [fs](https://npm.io/package/fs.md) 0.0.2
- [acho](https://npm.io/package/acho.md) ^2.4.1
- [semver](https://npm.io/package/semver.md) ^5.1.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^0.26.2
- [underscore](https://npm.io/package/underscore.md) ^1.8.3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.0 (latest) — 2015-12-21

## README

#jsonize

Keep your JSON structures versioned

[![Build Status](https://travis-ci.org/elenatorro/jsonize.svg)](https://travis-ci.org/elenatorro/jsonize)
[![Coverage Status](https://coveralls.io/repos/elenatorro/jsonize/badge.svg?branch=master&service=github)](https://coveralls.io/github/elenatorro/jsonize?branch=master)
[![Dependency Status](https://david-dm.org/elenatorro/jsonize/master.svg)](https://david-dm.org/elenatorro/jsonize/master)
[![devDependency Status](https://david-dm.org/elenatorro/jsonize/master/dev-status.svg)](https://david-dm.org/elenatorro/jsonize/master#info=devDependencies)
---

##Problem: 

* You are working with jsons to structure your content (for instance, default settings for your web application stored in the localstorage).
* You modify this structure, but the old structure saved in localstorage breaks the functionality of your web application.
* You have to modify manually the saved structure, or delete it in order to generate the new structure

##Solution:

* You create different versions of your data structure.
* Everytime you create a new version, you save it in a configuration file (.json)
* If you have an old version stored, jsonize updates your stored data to fit the new version (or new versions)

##Documentation:
(under construction)

###Download

```
$ npm install json-ize (--save-dev)
``` 

###Import

```
var jsonize = require('jsonize')
``` 

###Configuration

```
jsonize.init()
``` 
It creates a jsonize.json file with the default minimum configuration in the same path. If you pass a path to your config file, jsonize will use that configuration.

```
jsonize.init('mypath/myconfig.json')
``` 

Default minimum configuration:

    
```
{
  "structure": {
    "version": "0.1.0"
  },
  "versions": {
    "0.1.0": {
      "date": "2015-12-11T11:56:36.848Z", //date in ISOString format
      "description": "",
      "add": {},
      "delete": [],
      "modify": {}
    }
  }
}
``` 


###Usage

* You receive a data structure. This data structure must have a version field

```
// 'loadedStructure' contains the data you had stored
jsonize.set.structure(loadedStructure)
//loadedStructure is saved in the config structure
jsonize.update.last()
//update the structure to the last version in the config file
``` 

jsonize.update.last always updates the current last version also, so you can modify structure changes without creating a new version.
It also works recursively, so if your stored structure was 0.1.0 and last version is 0.3.0, but there was a version 0.2.0, it will update from 0.1.0 to 0.2.0 and then to 0.3.0.

* You want to create a new version

You can do it by using:

```
jsonize.set.new(structure, version) 
```

Where 'version' follows [semver syntax](https://github.com/npm/node-semver)

When adding a new version, the previous version should look like:

```
  "versions": {
    "0.1.0": {
      "date": "2015-12-11T11:56:36.848Z", //date in ISOString format
      "description": "",
      "add": {},
      "delete": [],
      "modify": {},
      "next":"patch"
    },
    "0.1.1": {
      "date": "2015-12-11T11:56:36.848Z", //date in ISOString format
      "description": "",
      "add": {},
      "delete": [],
      "modify": {}
    }
  }
```

As you can see, I added the attribute 'next' to the previous version, which contains the semver syntax that will be used to know the next version structure.


###Tests

To execute the tests, run:

```
$ npm test
```

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