All Projects → tjson → tjson.js

tjson / tjson.js

Licence: MIT license
JavaScript-compatible implementation of Tagged JSON (TJSON), written in TypeScript.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to tjson.js

Base62x
Base62x is an alternative approach to Base 64 without symbols in output.
Stars: ✭ 38 (-28.3%)
Mutual labels:  base64, base32, base16
BaseNcoding
Library for encoding of binary data into strings using base32, base85, base128 and other algorithms.
Stars: ✭ 42 (-20.75%)
Mutual labels:  base64, base32
scure-base
Secure, audited & 0-deps implementation of bech32, base64, base32, base16 & base58
Stars: ✭ 27 (-49.06%)
Mutual labels:  base64, base16
data-encoding
Efficient and customizable data-encoding functions in Rust
Stars: ✭ 92 (+73.58%)
Mutual labels:  base64, base32
multibase
multi base encoding/decoding utility
Stars: ✭ 15 (-71.7%)
Mutual labels:  base64, base32
moonblob
Binary serialization for moonscript + LuaJIT
Stars: ✭ 22 (-58.49%)
Mutual labels:  serialization
ruststep
A STEP toolkit for Rust
Stars: ✭ 77 (+45.28%)
Mutual labels:  serialization
elm-protobuf
protobuf plugin for elm
Stars: ✭ 93 (+75.47%)
Mutual labels:  serialization
GenericProtocol
⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐
Stars: ✭ 38 (-28.3%)
Mutual labels:  serialization
EndianBinaryIO
A C# library that can read and write primitives, enums, arrays, and strings to streams and byte arrays with specified endianness, string encoding, and boolean sizes.
Stars: ✭ 20 (-62.26%)
Mutual labels:  serialization
Xresources-themes
A big (huge) collection of rxvt / xterm terminal themes
Stars: ✭ 247 (+366.04%)
Mutual labels:  base16
php-json-api
JSON API transformer outputting valid (PSR-7) API Responses.
Stars: ✭ 68 (+28.3%)
Mutual labels:  serialization
moko-network
Network components with codegeneration of rest api for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 107 (+101.89%)
Mutual labels:  serialization
Apex.Serialization
High performance contract-less binary serializer for .NET
Stars: ✭ 82 (+54.72%)
Mutual labels:  serialization
parco
🏇🏻 generalist, fast and tiny binary parser and compiler generator, powered by Go 1.18+ Generics
Stars: ✭ 57 (+7.55%)
Mutual labels:  serialization
wxBase64
🏗️在小程序中使用 js-base64 库
Stars: ✭ 19 (-64.15%)
Mutual labels:  base64
avrow
Avrow is a pure Rust implementation of the avro specification https://avro.apache.org/docs/current/spec.html with Serde support.
Stars: ✭ 27 (-49.06%)
Mutual labels:  serialization
nason
🗜 Ultra tiny serializer / encoder with plugin-support. Useful to build binary files containing images, strings, numbers and more!
Stars: ✭ 30 (-43.4%)
Mutual labels:  serialization
GroBuf
Fast binary serializer
Stars: ✭ 56 (+5.66%)
Mutual labels:  serialization
LocalStorage
Configurable generic class for managing local data saved on device.
Stars: ✭ 24 (-54.72%)
Mutual labels:  serialization

tjson-js npm version Build Status Known Vulnerabilities MIT licensed

JavaScript-compatible implementation of Tagged JSON (TJSON), written in TypeScript.

TJSON is a microformat which supplements JSON with an extended set of data types by supplying a type "tag" embedded in object member names:

{
  "array-example:A<O>": [
    {
      "string-example:s": "foobar",
      "binary-example:d": "QklOQVJZ",
      "float-example:f": 0.42,
      "int-example:i": "42",
      "timestamp-example:t": "2016-11-06T22:27:34Z",
      "boolean-example:b": true
    }
  ],
  "set-example:S<i>": [1, 2, 3]
}

Help and Discussion

Have questions? Want to suggest a feature or change?

Requirements

tjson-js is presently targeting ES2017. This is because we soon plan on making use of the TC39 BigInt type when it becomes available, and want to make sure users of this library can handle modern ECMAScript versions.

Please make sure your JS runtime is ES2017 compliant, or use a transpiler like babel support older versions of ECMAScript.

Installation

Via npm:

npm install tjson-js

Via Yarn:

yarn install tjson-js

Import TJSON into your project with:

import TJSON from "tjson-js";

API

TJSON.parse()

The TJSON.parse() method parses a TJSON string, returning an Object described by the string. This method is analogous to JavaScript's built-in JSON.parse() method.

TJSON.parse(tjsonString[, decodeUTF8 = true])

Parameters

  • tjsonString: The string to parse, containing data serialized as TJSON.

  • decodeUTF8: instructs whether or not to first decode the TJSON string from UTF-8 before parsing it. By default UTF-8 will be automatically decoded to the engine's internal string representation (e.g. UCS-2). If you would like to skip automatic encoding conversions (e.g. because they happen at the I/O boundary) pass false.

Example

TJSON.parse('{"some-string-data:s":"Hello, world!","some-time-ago:t":"2017-04-22T20:40:53.182Z"}');
// Object { some-string-data: "Hello, world!", some-time-ago: Sat Apr 22 2017 13:40:53 GMT-0700 (PDT) }

TJSON.stringify()

The TJSON.stringify() method converts a JavaScript value to a TJSON string. This method is analogous to JavaScript's built-in JSON.stringify() method.

TJSON.stringify(value[, space = 0[, encodeUTF8 = true]])

Parameters

  • value: The value to convert to a TJSON string.

  • space: a String or Number object that's to insert white space into the output JSON string for readability purposes. For more information, please see the JSON.stringify() documentation.

  • encodeUTF8: instructs whether or not to encode the resulting document as UTF-8. The TJSON specification requires all confirming documents are encoded as UTF-8. If you would like to skip automatic encoding conversions (e.g. because they happen at the I/O boundary) pass false.

Type Conversions

The table below shows how TJSON tags map to JavaScript types:

Tag JavaScript Type Notes
O Object
A Array
S Set
b Boolean
d Uint8Array
f Number
i Number Will switch to TC39 BigInt when available
u Number Will switch to TC39 BigInt when available
s String
t Date

TJSON Spec Deviations

This is not (yet) a fully compliant TJSON parser. It contains the following defects, which can also be found in tjson.spec.ts's skipped examples:

  • 64-bit integer range unsupported: can't be supported in JavaScript until the TC39 BigInt type is available.
  • Repeated JSON object member names tolerated: the spec mandates that the names of JSON object members must be unique. This implementation silently ignores them.
  • Set uniqueness not guaranteed: the spec mandates that all members of sets must be unique. Unfortunately JavaScript's Set type and equality semantics allow members that are identical if compared by value.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tjson/tjson-js

License

Copyright (c) 2017 Tony Arcieri. Distributed under the MIT License. See LICENSE.txt for further details.

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].