Should a SVG be converted to JSON to be stored in the database?

by Fleuv   Last Updated October 11, 2018 14:05 PM - source

Consider an application where you can create and edit a SVG file (e.g.

How should the SVG be stored in the database?

With SVG (image/svg+xml)

Thus no further processing is required before the data is stored. But after the data is retrieved the SVG needs to be parsed so the application can set up event handlers and integrate the SVG with the functionality of the application.

With JSON (application/json)

The SVG data will have to be converted to a JSON object what will be stored in and retrieved from the database. When retrieving the JSON data from the database. The data must be converted back to SVG and while doing that the functionality of the application may be applied to the SVG.

Storing and retrieving the data isn't probably the part to be concerned about because it will take about the same amount of time and space to store or retrieve a SVG or JSON (depending on the differences in attribute/key length). Thus I guess the real performance issues occur at parsing the data. I know parsing JSON is easier and faster then XML, however when storing as SVG parsing of the data happens only once with JSON twice.

An other software engineer in my team told me to use JSON but couldn't substantiate why? Perhaps someone can substantiate why JSON should be chosen?

Answers 2


You should store the model the application uses to generate the svg. ie for a network diagram the various nodes and joins.

That way when you change the svg generation code the old models will generate the new graphics. Rather than have the old graphics load.

Essentially the svg is the view and you want to save the model.

October 11, 2018 13:42 PM

An other software engineer in my team told me to use JSON but couldn't substantiate why?

Maybe it was a joke? I can't think of any benefit to storing SVG inside JSON. None.

I would store SVG SVG format. Storing them in a file or blob storage system would be preferable to a database IMHO, but a database isn't a terrible option if the file sizes are small.

Dan Wilson
Dan Wilson
October 11, 2018 13:49 PM

Related Questions

Best approach for storing large 3d files?

Updated April 21, 2016 08:02 AM

How do different file generally store data?

Updated September 22, 2017 15:05 PM

Data storage for small application using XML

Updated September 13, 2018 14:05 PM