All Projects → tornqvist → Jazzon

tornqvist / Jazzon

Add some jazz to your JSON files

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Jazzon

Http Fake Backend
Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 253 (+565.79%)
Mutual labels:  json, mocking
Okhttp Json Mock
Mock your datas for Okhttp and Retrofit in json format in just a few moves
Stars: ✭ 231 (+507.89%)
Mutual labels:  json, mocking
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (+28.95%)
Mutual labels:  json, mocking
Wiremock
A tool for mocking HTTP services
Stars: ✭ 4,790 (+12505.26%)
Mutual labels:  json, mocking
Brutusin Rpc
Self-describing JSON-RPC web services over HTTP, with automatic API description based on JSON-Schema
Stars: ✭ 36 (-5.26%)
Mutual labels:  json
Node Quick Mock
🌞 基于Express的mock接口平台
Stars: ✭ 33 (-13.16%)
Mutual labels:  json
Data Forge Ts
The JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.
Stars: ✭ 967 (+2444.74%)
Mutual labels:  json
Parson
Lightweight JSON library written in C.
Stars: ✭ 965 (+2439.47%)
Mutual labels:  json
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (+0%)
Mutual labels:  mocking
Redux Json Router
Declarative, Redux-first routing for React/Redux browser applications.
Stars: ✭ 37 (-2.63%)
Mutual labels:  json
Gmock.py
'Google Mock' mocks generator based on libclang
Stars: ✭ 35 (-7.89%)
Mutual labels:  mocking
Lift
Lift is a Swift library for generating and extracting values into and out of JSON-like data structures.
Stars: ✭ 33 (-13.16%)
Mutual labels:  json
Json serializable.dart
Generates utilities to aid in serializing to/from JSON.
Stars: ✭ 979 (+2476.32%)
Mutual labels:  json
Jsontocodable
A generating tool from Raw JSON to Codable (Swift4) text written in Swift4.
Stars: ✭ 33 (-13.16%)
Mutual labels:  json
Val
golang JSON validation library.
Stars: ✭ 37 (-2.63%)
Mutual labels:  json
Jc
CLI tool and python library that converts the output of popular command-line tools and file-types to JSON or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
Stars: ✭ 967 (+2444.74%)
Mutual labels:  json
Json
Fork of golang's encoding/json: now with more validation and error context
Stars: ✭ 35 (-7.89%)
Mutual labels:  json
Java Jq
Lightweight Java wrapper around JQ, a flexible JSON processor available for multiple platforms
Stars: ✭ 37 (-2.63%)
Mutual labels:  json
Awesome Json
A curated list of awesome JSON libraries and resources.
Stars: ✭ 973 (+2460.53%)
Mutual labels:  json
Realtime Newsapi
Financial News Aggregator - Real Time & Query API for Financial News
Stars: ✭ 34 (-10.53%)
Mutual labels:  json

jazzon

Working with static JSON files for mocking data or whatever other purposes can be a real bore. Jazzon is a convenience utility for generating, concatenating and streamlining the handling of static JSON files.

Installation

$ npm install --save jazzon

Usage

In and of it self jazzon does nothing, really. It's sole purpose is to call registered plugins with the current state and identified helpers. Helpers can be chained passing the current state from one to the next.

To illustrate a most basic scenario, this is how one might use jazzon together with jazzon-uuid

const jazzon = require('jazzon');
const uuid = require('jazzon-uuid');

let data = { id: "@{ uuid }" };

jazzon.use(uuid());

jazzon
  .compile(data)
  .then(result => console.log(result)); // => {id: "6c84fb90-12c4-11e1-840d-7b25c5ee775a"}

In this scenario, jazzon encounters the helper uuid and calls each registered plugin (in this case jazzon-uuid) on it.

Helpers can also be chained using the pipe (|) symbol. Each chained helper gets the output (state) of the previous helper to operate on. To illustrate a more complex scenario, take these two models:

// user.json

{
  "id": "@{ uuid }",
  "name": "@{ name.findName }",
  "email": "@{ internet.email }",
  "username": "@{ internet.userName }"
}
// users.json

{
  "total": 3,
  "users": "@{ import(user.json) | pick(id, username) | repeat(3) }"
}

Running users.json through jazzon would produce something like this:

{
  "total": 3,
  "users": [{
    "id": "a76f535f-cbc6-4c09-8151-573e200c1dbf",
    "username": "Doug.Simonis28"
  }, {
    "id": "0a512648-c418-40a6-90ac-1bb5ef1e7fab",
    "username": "Virgil_Kunze"
  }, {
    "id": "88d6903f-d13b-4d16-877e-f906461c69aa",
    "username": "Grady.Koelpin"
  }]
}

Syntax

The syntax of helpers are very similar to JavaScript template strings to clearly illustrate their purpose. But do not confuse them as the pipe separator is not a valid JavaScript operator.

The string must start with @{ and end with }. Each helper is separated with a | symbol. Encountering an invalid template-ish string will throw an error.

Use this regexr to experiment with the template strings.

Plugins

Plugins should export a function that get's called once for every helper encountered by jazzon. The convention is to export a factory function that returns the plugin.

A plugin really is just a reducer that jazzon uses to process all the helpers. Therefore a plugin should always return a state, even if it does not manipulate the state. A switch statement does the job as so:

// myplugin.js

module.exports = function (otions) {
  return function (state, helper, args) {
    switch (helper) {
    case 'name':
      return args[0] || options.default;
    case 'wrap':
      return `Hello ${ state }!`;
    default:
      return state;
    }
  }
};
// myprogram.js

jazzon
  .use(myplugin({
    default: 'world'
  }))
  .compile({
    "first": "@{ name | wrap }",
    "second": "@{ name(Joe) | wrap }"
  })
  .then(result => console.log(result)); // => {"first": "Hello world!", "second": "Hello Joe!"}

Jazzon also supports async plugins. Under the hood, jazzon is using co so anything that co can handle, jazzon can handle. As so, other than just plain strings, a plugin may return a Promise, generator, generator function, function, object or array. Due to the awesome nature of co, objects and arrays may contain nestled objects/arrays containing Promises or any of the other supported types. See some of the plugins for examples of how this is achieved.

Availible plugins

To add your own plugin, add it to the list and make a pull request.

API

  • jazon.create(/*plugins*/) Creates a new instance of jazzon with optional list of plugins.
    • Returns jazzon
  • jazzon.use(plugin) Adds a plugin to be used when transforming template strings.
    • Returns jazzon
  • jazzon.compile(object) Iterates over the object looking for template strings to transform.
    • Returns a Promise
  • jazzon.plugins An list of registered helpers on this instance.
    • Returns an Array
    • Is immutable

TODO

  • [x] Add documentation
  • [x] Add wrapper for non-Promises returned from plugins
  • [x] Add test for plugins (generator/non-generator)
  • [x] Better error handling
  • [ ] Add CLI
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].