Convert svg to json

I want to be able to create an svg image in Illustrator and convert it to json in order to be able to use it with Raphael js, as shown below.

How can this be done without the server side of the script?

What I want:

[0,0,255.3,298.5,{type:'path',path:'M 35.3 257.2 C 34.4 245.7 45.4 234.1 48.5 223 C 53.6 204.3 55 185 60 166.2 C 69.5 131 69.6 97.1 89.1 65.1 C 103.4 41.7 129.5 5.3 161.3 19.7 C 184.6 30.3 181.3 59.2 188.9 78.9 C 207.5 127.3 228.6 184.8 230.3 237.3 C 231.3 268.6 202.8 261.3 178.2 264 C 149.2 267.1 120 269.6 91 272.2 C 84.2 272.8 75.8 274.2 69 273 C 60.9 271.6 28.9 259.9 31.3 249.2','fill':'#39b54a','stroke':'none','stroke-width':'0','fill-opacity':'1','stroke-opacity':'0'}]; 
+6
source share
3 answers

As I understand it, your problem is that Raphael does not work with imported SVG. There is a way to turn an SVG into a Raphael object, and then you can use it with the Raphael library. Check out this site: http://irunmywebsite.com/raphael/SVGTOHTML_LIVE.php

+2
source

Since svg is xml, you can use xml converter for json, for example: http://www.utilities-online.info/xmltojson

+1
source

Here's a solution using Python: https://github.com/gwintrob/svg-to-json

I came across this GitHub repo that uses JS but does not support a large SVG file: https://github.com/chrisfinch/svg-to-json

0
source

Source: https://habr.com/ru/post/946986/


All Articles