0

I am trying to automatize the creation of a json object from an ArrayBuffer[Array[String]](), where I have the field and its value saved, to throw it into a database (mongodb).

I can't find a way to do that.

I am using scala and json4s.

Would anyone know a method to answer this?

wipman
  • 581
  • 6
  • 22
  • 1
    Can you not just apply the native data structure into your MongoDB insert/update anyway? The driver should be able to handle it or at least re-cast. I know the play framework has fancy JSON things, but that should not be the "go to" option for working with a data structure you already have. And surely this is more than just an array of strings. If not then what do you expect the resulting document(s) to look like? – Blakes Seven Sep 15 '15 at 09:00
  • Great idea! I have succeeded in saving the object in the database using `DBObject` rather than creating a `json` object then saving it. Still, I would be interested in knowing how to automatize `json` from dynamic `String`s. – wipman Sep 15 '15 at 12:17
  • The general idea is "work native". You should never need to translate to JSON just to speak to MongoDB. Perhaps a misconception as MongoDB speaks "BSON" and not "JSON". – Blakes Seven Sep 15 '15 at 12:20
  • Good point. I got it wrong, I tried `json`. – wipman Sep 15 '15 at 12:38

0 Answers0