Hacker News new | ask | show | jobs
by seagreen 3600 days ago
I don't think so -- I'm looking for a database that will actually enforce a JSON schema for you -- I don't think Postgres has any built-in support for JSON schematization.

I could always do validation before inserting data, but that opens me up to error on my side which I'd like to avoid=)

2 comments

> I don't think Postgres has any built-in support for JSON schematization.

Guess again. You can use JSON functions¹ in constraints:

  create table foo (
    bar jsonb,
    constraint bar_count_is_positive check (bar->>'count' is not null and (bar->>'count')::integer >= 0)
  );
etc

You could probably write a tool pretty easily to convert a JSON schema to Postgres constraints.

1. https://www.postgresql.org/docs/current/static/functions-jso...

Slick, thanks!
You are trying to hammer a screw in. If what you want is a facility for the database to provide you with JSON on query, Postgres has a couple of functions for that, namely array_to_json and row_to_json: https://www.postgresql.org/docs/9.2/static/functions-json.ht...
I just want a key/value JSON database with schematization. If that's "trying to hammer a screw" then so be it.
May I ask why would you insist on such a thing? Is it about avoiding SQL?
I'd like access to JSON Schema's impressive tooling. I haven't seen anything like this for SQL schemas: http://jeremydorn.com/json-editor/

(Though if it exists please tell me, I'd be very interested!)

Don't know for Web-Applications, but for Windows Applications there are tons of framework, which will create GUIs for you, given your Model.

One very good, which I extensively used in my previous position was DevExpress (https://www.devexpress.com/Products/NET/Controls/WPF/Editors...).