Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
develohpanda committed May 10, 2019
1 parent 5af859c commit 66717b4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

json-order allows for conversion between JS Objects and a JSON string while keeping property order, controlled via a property map. **All manner of nesting is supported**.

# Usage
## Usage

## `parse`
### `parse`
To parse a JSON string and generate a map:
```js
const result = orderedJson.parse('{...}');
```

`result.object` will contain a JS object while `result.map` will contain the generated property map.

## `stringify`
### `stringify`

To stringify a JS object maintaining a particular property order:
```js
const jsonString = orderedJson.stringify(srcObj, map, 2);
```

### Parameters
#### Parameters
- `srcObj`: an object with the properties in any order
- `map`: the property map generated by `parse` above
- `space` [optional]: a `number` used to insert white space into the output JSON string for readability purposes, as per the `JSON.stringify` [documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters).

# Example
## Example

An object with a particular property order:
```json
Expand Down Expand Up @@ -55,7 +55,7 @@ Will generate a lookup object like:
}
```

# Why?
## Why?

JS Objects in JavaScript do keep their property insertion order (this behaviour is dependant on the JS engine), however this behaviour is not guaranteed by other systems you may interchange that object with.

Expand All @@ -67,7 +67,7 @@ There are several solutions to this problem, (eg. storing the data in a differen

This particular implementation is in reference to the approach suggested for feature [1046](https://github.com/getinsomnia/insomnia/issues/1046#issuecomment-486419705) in [Insomnia](https://github.com/getinsomnia/insomnia).

# Contributing
## Contributing
Please raise issues or feature requests via the [Github issue tracker](https://github.com/develohpanda/json-order/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)

Feel free to submit a pull request with your change!
Expand Down

0 comments on commit 66717b4

Please sign in to comment.