Jason, a simple typesafe JSON ORM for your standalone application needs

Jason, a simple typesafe JSON ORM for your standalone application needs

Why did the JSON object go to therapy? Because it had trouble parsing its feelings.

Background

I was making a side project which required a Database, the project was a self-hosted type of application for which the end user would have to host it locally by himself to use the project, it wouldn't make much sense if the end user had to do this much hassle to use my project! So I saw a problem and I solved it, if it was a problem for me, I'm sure someone else also needs something like this.

But there are already ORMs in the market for JSON you say? Well, I didn't find any of them good for my liking (personal preference), I liked the Mongoose library for mongoDB in which you can just pass the interface of your model into the constructor and it returns an object with CRUD methods.

This library is bare minimum and complex queries should be implemented by your own logic on top of the library like getting the records by Jason and applying your own logic to perform complex queries on them, (not keeping time complexity in mind because it's supposed to be for standalone software or very small scale project).

But I really enjoyed working on this so I might try to build a query builder on top of it!

Installing

# using npm
npm install @probablyarth/jason
# using yarn
yarn add @probablyarth/jason

Here is an example of how to use the library

import { Init, Model } from "@probablyarth/jason";

Init("path/to/database.json");

interface IUser {
  name?: string;
  age?: number;
}

const userModel = new Model<IUser>("users");

const userId = userModel.insertOne({
  name: "probablyarth",
  age: 17,
});

const user = userModel.findById(userId);

console.log(user);

You can also use it without types,

import { Init, Model } from "@probablyarth/jason";

Init("path/to/database.json");

const userModel = new Model("users");

const userId = userModel.insertOne({
  name: "probablyarth",
  age: 17,
});

const user = userModel.findById(userId);

console.log(user);

You can go here for more examples

Check it out on GitHub!

Jason on GitHub

It'd be great if you could leave a ⭐️ on GitHub! Some traction would help in fine-tuning this library!

TL: DR;

Do you like the mongoose library but need an easy-to-set-up database solution for your standalone application? Jason may be the right option for you!