npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kson_org/kson

v0.2.1

Published

KSON - Extended JSON format with comments and more

Readme

JavaScript/TypeScript bindings for kson-lib API

KSON (Kson Structured Object Notation) combines the best of JSON and YAML—robust and efficient like JSON, clean and readable like YAML.

Example Usage

Write some code:

import { Kson, Result } from '@kson_org/kson';

const kson = Kson.getInstance();

// Convert KSON to JSON
const result = kson.toJson('key: [1, 2, 3, 4]');
if (result instanceof Result.Success) {
  console.log(result.output);
}

Running this should print the following:

{
  "key": [
    1,
    2,
    3,
    4
  ]
}

TypeScript Usage

This package includes TypeScript definitions out of the box:

import { Kson, Result, FormatOptions, IndentType, FormattingStyle } from 'kson';

const kson = Kson.getInstance();

const ksonString = `
  person:
    name: 'Leonardo Bonacci'
    nickname: Fibonacci
    age: 42
`;

// Convert KSON to JSON
const jsonResult: Result = kson.toJson(ksonString);
if (jsonResult instanceof Result.Success) {
  const data = JSON.parse(jsonResult.output);
  console.log(data);
} else if (jsonResult instanceof Result.Failure) {
  console.error('Errors:', jsonResult.errors);
}

// Format KSON (returns string directly)
const formatted: string = kson.format(ksonString);
console.log(formatted);

// Format with options
const options = new FormatOptions(
  new IndentType.Spaces(2),
  FormattingStyle.PLAIN
);
const formattedWithOptions = kson.format(ksonString, options);
console.log(formattedWithOptions);

// Convert to YAML
const yamlResult = kson.toYaml(ksonString);
if (yamlResult instanceof Result.Success) {
  console.log(yamlResult.output);
}

API Reference

Core Methods

  • toJson(kson: string, retainEmbedTags?: boolean): Result Converts KSON to formatted JSON. Returns a Result which can be either:

    • Result.Success with an output property containing the JSON string
    • Result.Failure with an errors property containing a list of error messages
  • toYaml(kson: string, retainEmbedTags?: boolean): Result Converts KSON to YAML format. Returns a Result with Success/Failure variants.

  • format(kson: string, formatOptions?: FormatOptions): string Formats KSON string according to specified style. Returns the formatted string directly.

  • analyze(kson: string): Analysis Analyzes KSON and returns diagnostic information including tokens and any errors.

  • parseSchema(schemaKson: string): SchemaResult Parses and validates a KSON schema. Returns a SchemaResult which can be:

    • SchemaResult.Success with a schemaValidator for validating KSON documents
    • SchemaResult.Failure with error messages

Helper Types

  • FormatOptions: Configuration for formatting

    • indentType: Either IndentType.Spaces(size) or IndentType.Tabs
    • formattingStyle: One of FormattingStyle.PLAIN, FormattingStyle.DELIMITED, or FormattingStyle.COMPACT
  • Result: Success/Failure union type for operations that can fail

    • Result.Success: Contains output property with the result string
    • Result.Failure: Contains errors property with error messages
  • SchemaResult: Success/Failure for schema parsing

    • SchemaResult.Success: Contains schemaValidator for validating documents
    • SchemaResult.Failure: Contains error messages

KSON Syntax Highlights

# Comments are supported
person:
  name: 'Leonardo Bonacci'
  nickname: Fibonacci  # Quotes are optional for simple strings
  age: 42

  # Arrays can be written in multiple styles
  favorite_books:
    - title: Elements
      author: Euclid
    - title: Metaphysics
      author: Aristotle

  # Nested arrays and complex values
  favorite_numbers: [0, 1, 1, 2, 3, 5, 8]
  golden_ratio: '(1 + √5)/2'

Environment Support

This package uses conditional exports to provide optimized builds for different environments:

  • Node.js: ES modules optimized for server-side use
  • Browser: ES modules optimized for client-side use
  • TypeScript: Full type definitions included

The correct version is automatically selected based on your environment.

Platform Compatibility

The JavaScript bindings are compiled from Kotlin/JS and work across all modern JavaScript environments. The package includes:

  • Pre-compiled ES modules for both browser and Node.js
  • TypeScript type definitions
  • Source maps for debugging

No additional setup or native binaries are required - everything works out of the box on all platforms that support JavaScript.

Links

License

Apache-2.0