All Projects → avocode → json-immutable

avocode / json-immutable

Licence: MIT license
Immutable.JS structure-aware JSON serializer/deserializer

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to json-immutable

React Native Immutable List View
📜 Drop-in replacement for ListView, FlatList, and VirtualizedList.
Stars: ✭ 206 (+795.65%)
Mutual labels:  immutable, immutablejs
universal-routed-flux-demo
The code in this repo is intended for people who want to get started building universal flux applications, with modern and exciting technologies such as Reactjs, React Router and es6.
Stars: ✭ 31 (+34.78%)
Mutual labels:  immutable, immutablejs
extendable-immutable
Wrapper classes around Immutable.js that turn it inheritable
Stars: ✭ 58 (+152.17%)
Mutual labels:  immutable, immutablejs
Typed Immutable
Immutable and structurally typed data
Stars: ✭ 263 (+1043.48%)
Mutual labels:  immutable, immutablejs
next-react-boilerplate
🔥 NextJS with additional tech feature like react-boilerplate. Demo >>
Stars: ✭ 20 (-13.04%)
Mutual labels:  immutable, immutablejs
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (+913.04%)
Mutual labels:  immutable, immutablejs
react-redux-immutable-webpack-ssr-starter
React + React-Router 4 + Redux + ImmutableJS + Bootstrap + webpack 3 with with Server side rendering, Hot Reload and redux-devtools STARTER
Stars: ✭ 21 (-8.7%)
Mutual labels:  immutable, immutablejs
abilitysheet
This app is ability sheet for beatmania iidx music of level 12.
Stars: ✭ 38 (+65.22%)
Mutual labels:  immutablejs
relite
a redux-like library for managing state with simpler api
Stars: ✭ 60 (+160.87%)
Mutual labels:  immutable
Mappable
flexible JSON to Model converter, specially optimized for immutable properties
Stars: ✭ 27 (+17.39%)
Mutual labels:  immutable
dot-wild
Use powerful dot notation (dot path + wildcard) to manipulate properties of JSON
Stars: ✭ 28 (+21.74%)
Mutual labels:  immutable
dobux
🍃 Lightweight responsive state management solution.
Stars: ✭ 75 (+226.09%)
Mutual labels:  immutable
optic
An Erlang/OTP library for reading and updating deeply nested immutable data.
Stars: ✭ 34 (+47.83%)
Mutual labels:  immutable
blockchain-pen
BlockchainPen - a web app for writing immutable messages to the blockchain.
Stars: ✭ 14 (-39.13%)
Mutual labels:  immutable
react-redux-cats
React and Redux with cats
Stars: ✭ 23 (+0%)
Mutual labels:  immutable
Accessors.jl
Update immutable data
Stars: ✭ 73 (+217.39%)
Mutual labels:  immutable
isomorphic-react-redux-saga-ssr
Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting
Stars: ✭ 19 (-17.39%)
Mutual labels:  immutable
fp-ts-cheatsheet
FP-TS Cheat Sheet
Stars: ✭ 276 (+1100%)
Mutual labels:  immutable
bs-immutablejs
Reason + BuckleScript bindings to Immutable.js
Stars: ✭ 28 (+21.74%)
Mutual labels:  immutable
molecule
⚛️ –  – ⚛️ Boilerplate for cross platform web/native react apps with electron.
Stars: ✭ 95 (+313.04%)
Mutual labels:  immutablejs

JsonImmutable

Build Status

Immutable.JS structure-aware JSON serializer/deserializer built around the native JSON API.

Motivation

By using the native JSON API, Immutable.JS structures are serialized as plain objects and arrays with no type information. The goal was to preserve both Immutable.JS Iterable types (maps, lists, etc.) and Record types. immutable.Map supports and preserves key types while plain JavaScript object keys are coerced to strings. These types should also preserved.

Usage

Plain Objects and Primitive Types

const data = { 'a': 'b', 'c': 123, 'd': true }

// Serialize
const json = serialize(data)
// json == '{"a":"b","c":123,"d":true}'

// Deserialize
const result = deserialize(json)

Native Object Types

const data = { 'created_at': new Date('2016-09-08'), 'pattern': /iamnative/g }

// Serialize
const json = serialize(data)
// json == '{"created_at":{"__date":"2016-09-08T00:00:00Z"},"pattern":{"__regexp":"/iamnative/g"}}'

// Deserialize
const result = deserialize(json)

Immutable Records

const SampleRecord = immutable.Record(
  { 'a': 3, 'b': 4 },
  'SampleRecord'
)

const data = {
  'x': SampleRecord({ 'a': 5 }),
}

// Serialize
const json = serialize(data)
// json == '{"x":{"__record":"SampleRecord","data":{"a":5}}}'

// Deserialize
const result = deserialize(json, {
  recordTypes: {
    'SampleRecord': SampleRecord
  }
})

Record types can be named. This is utilized by the serializer/deserializer to revive immutable.Record objects. See the SampleRecord name passed into immutable.Record() as the second argument.

NOTE: When an unknown record type is encountered during deserialization, an error is thrown.

General Immutable Structures

const data = {
  'x': immutable.Map({
    'y': immutable.List.of(1, 2, 3)
  }),
}

// Serialization
const json = serialize(data)
// json == '{"x":{"__iterable":"Map","data":[["y",{"__iterable":"List","data":[1,2,3]"}]]}}'

// Deserialize
const result = deserialize(json)
  • Immutable structures, plain objects and primitive data can be safely composed together.

  • immutable.Map key type information is preserved as opposed to the bare JSON API.

NOTE: When an unknown Immutable iterable type is encountered during deserialization, an error is thrown. The supported types are List, Map, OrderedMap, Set, OrderedSet and Stack.

API

  • serialize()

    Arguments:

    • data: The data to serialize.
    • options={}: Serialization options.
      • pretty=false: Whether to pretty-print the result (2 spaces).

    Return value:

    • string: The JSON representation of the input (data).
  • deserialize()

    Arguments:

    • json: A JSON representation of data.
    • options={}: Deserialization options.
      • recordTypes={}: immutable.Record factories.

    Return value:

    • any: Deserialized data.

Streaming API

  • createSerializationStream()

    Arguments:

    • data: The data to serialize.
    • options={}: Serialization options.
      • pretty=false: Whether to pretty-print the result (2 spaces).
      • bigChunks=false: Whether the serialized data should only be split into chunks based on the reader speed. By default, each data structure level is processed in its own event loop microtask which.
        • NOTE: When bigChunks=true, a (possibly substantial) portion of the data is serialized synchronously.

    Return value:

    • stream.PassThrough<!Buffer>: A readable stream emitting the JSON representation of the input (data).

Running Tests

  1. Clone the repository.
  2. npm install
  3. npm test
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].