What are Advantages / Disadvantages of Storing Data as JSON in Database?

I'm currently experimenting with storing the data as JSON in the database. I found out that latest versions of database engines allow storing of data JSON or JSON by data type. I'm wondering what exactly are the advantages and disadvantages of storing data as JSON vs. storing it as a regular text-string?

I did try finding information about it - but could not find anything that directly answers the question I have. 

PS: My dilemma is about retrieving the data as JSON vs. retrieving it as plain text string. Ultimately, JSON itself looks like a plain text string to my eyes. 

Tagging: #-Link-Snipped-# , #-Link-Snipped-# (add a photo, buddy!) for responses. 

Replies

  • Prasad Ajinkya
    Prasad Ajinkya

    JSON is good for storing objects/documents in the DB when you are not sure of the structure of the object. The beauty of this is that you can store your data hierarchically.

    JSON can be a plain string, but if you parse the string (json_decode() in PHP, JSON.parse() in JS, etc), then you get an object which can be manipulated. This is catching on because these JSON objects can match directly with controllers and views.

    Hope this helps.

  • Kaustubh Katdare
    Kaustubh Katdare

    #-Link-Snipped-# - right. So far, the only advantage I've realized is that the data obtained from the database can be directly employed as an object. So that works. Was wondering if there are any specific cases where data needs to be stored as JSON. Thank you for the reply. 

  • Prasad Ajinkya
    Prasad Ajinkya
    1. Where your object schema is unknown during design time and becomes relevant in run-time. 
    2. Where your object schema changes over a period of time (progressive profiling, document completion, multi-layer form fills)
    3. Where each document/tupple is standalone and doesnt have to rely on multiple joins.

    Let's say that we create a Pay Per Use REST API (The API Economy) .. and for sake of compliance and billing have to store each Request/Response objects. So a simple case could be store both the request and response objects as JSON documents within a single document, and keep a collection of those. 

    The thing about specifications is that if you keep specifying these, then the very reason why you would require this is eliminated. Since with those sharper specifications, you could always design an optimised RDBMS.

You are reading an archived discussion.

Related Posts

Rani Therapeutics just achieved one of its most significant milestones since it was spun out of InCube Lab in 2012. The San Jose, CA-based company just finished conducting the first...
Medgadget says: Verily, the life sciences research arm of Alphabet, and Google, the original part of the now giant company, are launching in India a screening program to identify people...
Machine Design says: welding is a heating process that uses an electric arc to join two metal parts together. A common process, yes—but by no means a simple one. There...
Hello,mam.Am persuing my b tech at CMR College of engineering and technology (autonomous) and I wanna do a summer internship at BHEL after this semester i.e 2-2.I am from ECE...
Hey Everyone, Would you please suggest me a good laptop for studying purpose. Actually I want to buy a laptop for my sister, she is studying in B.C.A first year....