Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huanghaiyang/jsonmock
json data mock framework
https://github.com/huanghaiyang/jsonmock
fakerjs json mock mock-data
Last synced: 6 days ago
JSON representation
json data mock framework
- Host: GitHub
- URL: https://github.com/huanghaiyang/jsonmock
- Owner: huanghaiyang
- License: mit
- Created: 2016-08-01T07:51:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-04T02:01:37.000Z (over 8 years ago)
- Last Synced: 2024-04-14T18:29:06.496Z (7 months ago)
- Topics: fakerjs, json, mock, mock-data
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonmock
json mock framework## install
```
npm install jsonmock --save
```## test
```
npm install
npm test
```## build
```
npm run build
```## how to use
```javascript
var jsonmock = require('../lib/index')
var user = jsonmock('./tests/data/user.json')
```user.json must be like this:
```json
{
"name": chance.name(),
"age": chance.age(),
"cf": chance.cf(),
"birthday": chance.birthday(),
"location": {
"address": chance.address(),
"country": chance.country(),
"phone": chance.phone(),
"city": faker.address.city(),
"streetName": (() => {
return faker.address.streetName()
})()
}
}
```you can use [chance](http://chancejs.com/) or [faker](http://marak.github.io/faker.js/) to generate a mock data, or use ```(()=>{})()``` to caculate, but it does not support other libs or funcs.
if you want get an user array, please use like this:
```javascript
var users = jsonmock('./tests/data/user.json', {
length: 10
})
assert.equal(users.length, 10)
```
user ```@import``` to include another ```.json```, let's watch ```web.json``````json
{
"domain": chance.domain(),
"ip": @import "./tests/data/ip.json"
}
```
ip.json
```
{
"ipv4": chance.ip(),
"ipv6": chance.ipv6()
}
```
remeber, it does not support recursive ```@import``` in ```ip.json```you may use jsonmock to mock paganition...