How to store JSON - as object or string?

141 views
Skip to first unread message

Joao Barcia

unread,
Jun 26, 2015, 8:09:50 AM6/26/15
to orient-...@googlegroups.com
We are building an educational platform. The content of our lessons is described in JSON. We can store them as String and afterwards convert them to JSON objects on the web app side.

I was just wondering if there is a more elegant approach and a possibility to store them directly as JSON objects. On some older threads (2011/2012) I saw some recommendations on storing them as embedded objects, but this type does not seem to exist anymore.

I have tried as Embedded, Embedded Lists which returned an error when I try to save our object. Embedded Sets seems to be able to store it, although I'm not sure why. What would be the correct way of achieving this

Ricardo M. Vilchis

unread,
Jun 26, 2015, 9:16:55 PM6/26/15
to orient-...@googlegroups.com

What is the query you try?

I recently have a similar problem with this:

insert into post set shares = {"fb_count":0, "tw_count":5}

and I solved adding @type:

insert into post set shares = {"@type": "d", "fb_count":0, "tw_count":5}

RMV

Enviado desde mi reloj Casio.

--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

alessand...@gmail.com

unread,
Jun 29, 2015, 3:34:34 AM6/29/15
to orient-...@googlegroups.com
Hi Joao,
this is an example of code for Embedded List from java api

OrientGraph g=new OrientGraph(currentPath);

OClass cl=g.createVertexType("Person", "V");
cl.createProperty("name", OType.STRING);
cl.createProperty("lista", OType.EMBEDDEDLIST);
List<Auto> lista1=new ArrayList<Auto>();
lista1.add(new Auto("Ferrari"));
lista1.add(new Auto("Lamborghini"));
Gson gson = new Gson();
String json = gson.toJson(lista1);
OrientVertex v1=g.addVertex("class:Person");
v1.setProperties("name","alessandro");
v1.setProperties("lista",json);

g.shutdown();

Regards,
Alessandro

Joao Barcia

unread,
Jun 29, 2015, 9:41:15 AM6/29/15
to orient-...@googlegroups.com
Thanks guys. We are mostly using studio for our db input for the moment. After a few tests it seems that creating an "embedded set" property in our "lesson" class worked perfectly.

Below is an example of what we put inside of it. It is also being loaded nicely as a JSON object from our client side in meteor

Let me know if there is any reason why this is incorrect/bad practice.

Cheers

[
    {
        "type": "exerciseString",
        "question": "What is blah blah?",
        "answers": [
            "answer 1 string",
            "answer 2 string",
            "answer 3 string"
        ]
    },

    {
        "type": "explanation",
        "contents": [
            {
                "text": "Welcome to this unit with text and stuff"
            },
            {
                "img": "/images/mathsImg.jpg"
            },
            {
                "text": "Go forward and learn more amazing things"
            }
        ]
    }
]



--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/7a3uLdLn7KY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages