Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

danson

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

danson

Danson

Source
npmnpm
Version
0.7.0
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

danSON

Progressive JSON

🤝 Code of Conduct: Kept 🧪 Coverage 📝 License: MIT 📦 npm version 💪 TypeScript: Strict

About

danSON is a progressive JSON serializer and deserializer that can serialize and deserialize arbitrary objects into JSON.

Features

  • Streaming of Promises, AsyncIterables, and ReadableStreams
  • Custom serializers / deserializers
  • De-duplication of objects (optional)
  • Circular references

Examples

Try the example on StackBlitz

Serializing custom objects

import { Temporal } from "@js-temporal/polyfill";
import { parseSync, stringifySync } from "danson";

const source = {
	instant: Temporal.Now.instant(),
};

const stringified = stringifySync(source, {
	serializers: {
		"Temporal.Instant": (value) => value.toJSON(),
	},
	space: 2,
});
/*
{
	"json": {
		"instant": {
			"_": "$",
			"type": "Temporal.Instant",
			"value": "2025-06-13T15:24:51.30029128Z"
		}
	}
}
*/

const result = parseSync<typeof source>(stringified, {
	deserializers: {
		"Temporal.Instant": (value) => Temporal.Instant.from(value as string),
	},
});

Streaming Promises

Promise example input

const source = {
	foo: "bar",
	promise: (async () => {
		await sleep(1000);
		return "hello promise";
	})(),
};

const stringified = stringifySync(source, {
	space: 2,
});
for await (const chunk of stringified) {
	console.log(chunk);
}

Promise example output

{
	"json": {
		"foo": "bar",
		"promise": {
			"_": "$", // informs the deserializer that this is a special type
			"type": "Promise", // it is a Promise
			"value": 1, // index of the Promise that will come later
		},
	},
}
[
	1, // index of the Promise
	0, // Promise succeeded (0 = success, 1 = failure)
	{
		"json": "hello promise"
	}
]

Streaming AsyncIterables

AsyncIterable example input

const source = {
	asyncIterable: (async function* () {
		yield "hello";
		yield "world";

		return "done";
	})(),
};

const stringified = stringifySync(source, {
	space: 2,
});
for await (const chunk of stringified) {
	console.log(chunk);
}

AsyncIterable example output

{
	"json": {
		"foo": "bar",
		"asyncIterable": {
			"_": "$",
			"type": "AsyncIterable",
			"value": 0
		}
	}
}
[
	0,
	0,
	{
		"json": "world"
	}
]
[
	0, // index of the AsyncIterable
	2,
	{
		"json": "done"
	}
]

Installation

npm install danson

Usage

Contributors

💝 This package was templated with create-typescript-app using the Bingo framework.

FAQs

Package last updated on 16 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts