Description
JSON is easy for humans to read and write... in theory. In practice JSON gives us plenty of opportunities to make mistakes without even realizing it.
Hjson is a syntax extension to JSON. It's NOT a proposal to replace JSON or to incorporate it into the JSON spec itself. It's intended to be used like a user interface for humans, to read and edit before passing the JSON data to the machine.
hjson-js alternatives and similar modules
Based on the "Database" category.
Alternatively, view hjson-js alternatives based on common mentions on social networks and blogs.
-
SheetJS js-xlsx
๐ SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs -
TypeORM
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms. -
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB -
Sequelize
Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i. -
Knex
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use. -
MikroORM
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, MS SQL Server, PostgreSQL and SQLite/libSQL databases. -
Waterline
An adapter-based ORM for Node.js with support for mysql, mongo, postgres, mssql (SQL Server), and more -
SignalDB
SignalDB is a local JavaScript database with a MongoDB-like interface and TypeScript support, enabling optimistic UI with signal-based reactivity across multiple frameworks. It integrates easily with libraries like Angular, Solid.js, Preact, and Vue, simplifying data management with schema-less design, in-memory storage, and fast queries. -
RediBox Core
Modular Redis connection and PUBSUB subscription manager for node. Easily extendable. Built for performance, powered by ioredis. -
Node Postgres Extras
NodeJS PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more. -
@Sugoi\orm
SugoiJS ORM module typescript based - Simple solution for object handling with predefined lifecycle
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of hjson-js or a related project?
Popular Comparisons
README
hjson-js
Hjson, a user interface for JSON
JSON is easy for humans to read and write... in theory. In practice JSON gives us plenty of opportunities to make mistakes without even realizing it.
Hjson is a syntax extension to JSON. It's NOT a proposal to replace JSON or to incorporate it into the JSON spec itself. It's intended to be used like a user interface for humans, to read and edit before passing the JSON data to the machine.
{
# specify rate in requests/second (because comments are helpful!)
rate: 1000
// prefer c-style comments?
/* feeling old fashioned? */
# did you notice that rate doesn't need quotes?
hey: look ma, no quotes for strings either!
# best of all
notice: []
anything: ?
# yes, commas are optional!
}
The JavaScript implementation of Hjson is based on JSON-js. For other platforms see hjson.github.io.
Install from npm
npm install hjson
Usage
var Hjson = require('hjson');
var obj = Hjson.parse(hjsonText);
var text2 = Hjson.stringify(obj);
To keep comments intact see API.
From the Commandline
Install with npm install hjson -g
.
Usage:
hjson [OPTIONS]
hjson [OPTIONS] INPUT
hjson (-h | --help | -?)
hjson (-V | --version)
INPUT can be in JSON or Hjson format. If no file is given it will read from stdin.
The default is to output as Hjson.
Options:
(-j | -json) output as formatted JSON.
(-c | -json=compact) output as JSON.
Options for Hjson output:
-sl output the opening brace on the same line
-quote quote all strings
-quote=all quote keys as well
-js output in JavaScript/JSON compatible format
can be used with -rt and // comments
-rt round trip comments
-nocol disable colors
-cond=n set condense option (default 60, 0 to disable)
Domain specific formats are optional extensions to Hjson and can be enabled with the following options:
+math: support for Inf/inf, -Inf/-inf, Nan/naN and -0
+hex: parse hexadecimal numbers prefixed with 0x
+date: support ISO dates
Sample:
- run
hjson -j test.hjson > test.json
to convert to JSON - run
hjson test.json > test.hjson
to convert to Hjson - run
hjson test.json
to view colorized output
API
The API is the same for the browser and node.js version.
NOTE that the DSF api is considered experimental
Hjson.parse(text, options)
This method parses JSON or Hjson text to produce an object or array.
- text: the string to parse as JSON or Hjson
- options: object
- keepWsc: boolean, keep white space and comments. This is useful if you want to edit an hjson file and save it while preserving comments (default false)
Hjson.stringify(value, options)
This method produces Hjson text from a JavaScript value.
- value: any JavaScript value, usually an object or array.
- options: object
- keepWsc: boolean, keep white space. See parse.
- condense: integer, will try to fit objects/arrays onto one line. Default 0 (off).
- bracesSameLine: boolean, makes braces appear on the same line as the key name. Default false.
- emitRootBraces: boolean, show braces for the root object. Default true.
- quotes: string, controls how strings are displayed. (setting separator implies "strings")
- "min": no quotes whenever possible (default)
- "keys": use quotes around keys
- "strings": use quotes around string values
- "all": use quotes around keys and string values
- multiline: string, controls how multiline strings are displayed. (setting quotes implies "off")
- "std": strings containing \n are shown in multiline format (default)
- "no-tabs": like std but disallow tabs
- "off": show in JSON format
- separator: boolean, output a comma separator between elements. Default false
- space: specifies the indentation of nested structures. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as '\t' or ' '), it contains the characters used to indent at each level.
- eol: specifies the EOL sequence (default is set by Hjson.setEndOfLine())
- colors: boolean, output ascii color codes
- sortProps: boolean, when serializing objects into hjson, order the keys based on their UTF-16 code units order. Default false.
Hjson.endOfLine(), .setEndOfLine(eol)
Gets or sets the stringify EOL sequence ('\n' or '\r\n'). When running with node.js this defaults to os.EOL.
Hjson.rt { parse, stringify }
This is a shortcut to roundtrip your comments when reading and updating a config file. It is the same as specifying the keepWsc option for the parse and stringify functions.
Hjson.version
The version number.
require-hook
Require a config file directly.
require("hjson/lib/require-config");
var cfg=require("./config.hjson");
modify & keep comments
You can modify a Hjson file and keep the whitespace & comments intact (round trip). This is useful if an app updates its config file.
// parse, keep whitespace and comments
// (they are stored in a non enumerable __COMMENTS__ member)
var data = Hjson.rt.parse(text);
// modify like you normally would
data.foo = "text";
// convert back to Hjson
console.log(Hjson.rt.stringify(data));
Build
To run all tests and create the bundle output, first install the dev dependencies with npm i
and then run npm run build
.
History
[see history.md](history.md)
*Note that all licence references and agreements mentioned in the hjson-js README section above
are relevant to that project's source code only.