Json newbie: how to store json objects

[From a json newbie]
What is the proper way to store json objects, in cbl?
Do I simply store it as a string in the document properties?
Do I use the JsonObject or JsonDocument classes?
A simple example please.

Thank you much.
nat

Everything stored in CBL is a JSON object. You should not encode the JSON into string form; that’s CBL’s job. Instead use objects that serialize to JSON. The details depend on the platform you’re using.

Currently relevant to CBL on Android.
Thanks.

Java’s not my forte, but I believe you use Map<String,Object> for dictionaries and List<Object> for arrays. Plus String, Number, etc.

Point of the question was that; Do I store the data directly in the properties Map<String, Object> returned from and is inherent in the Couchbase document, db.getDocument(id).getProperties(), (as it seems from your answer);
OR
Do I first instantiate some JSon object class, wrap all my stuff in it and store that in the properties Map?

Thanks
nat

We have documentation that shows how to do this, including examples in all the supported languages.

Ok. Will study it again.
Thanks.
nat

Also, you might be interested in this blog: Exploring Couchbase Mobile on Android: Object Mapping

Nice discussion.
Thanks.
nat

Could I load my JSON data file into Couchbase Lite db from Android without parsing it?

Nope. Parse it to the usual POJOs first.

Could you suggest a good API parser or a best way to load my JSON data file ( the file size is about 20 MB) into Couch base lite from my Android App?

thanks :slight_smile:

Responded to your other post

What boggles me since couchbase is already using json to store the data why would we have to parse the json ourselves.

We have a a json object, we convert it to a POJO, we again set the values into a couchbase document just so it can be converted into a json file all over again.

couchbase is already using json to store the data

This is a misconception. Couchbase does not store JSON on the disk, it just allows you to interact with the data as if it were JSON, using JSON types.

The format is Fleece, if you’re curious. It’s much faster to parse than JSON, which helps a lot in doing queries.

Hello I am also new and would like to better understand this topic.
The couchbase lite library is used for mobile (or UWP) storage.
Now, as the name also suggest, it seems to me that it is using an sqlite database to actually store data on mobile devices, is this correct?
As @borrrden says:

Are you actually referring to the Lite sdk or the server sdk?

Couchbase Lite uses SQLite as the underlying database. That may seem weird, but SQLite is already installed on all mobile platforms, and is lightweight and fast. The naming is coincidental; both SQLite and Couchbase Lite use the name “light” to indicate that they’re lightweight, but we didn’t name Couchbase Lite after SQLite.

@borrrden was referring to Couchbase Lite. We use a more compact and efficient data format called Fleece internally. Couchbase Server stores JSON directly. Server and Lite have very different operating requirements so different optimizations make sense. The fact that we use Fleece is totally transparent, though; it doesn’t affect the API.

Ok, I see. Thank you for your reply.
IMHO I think it will make sense and help users a lot with the mapping if we could store objects passing a string containing JSON (this would then be parsed in the background to Fleece).
Is it possible somehow that I cannot see?
Thank you

Not at this time. You will be specifying the JSON document as a map/dictionary (whatever is native to your language). It is transformed into Fleece by Couchbase Lite. Since you mentioned UWP, I’m assuming you are interested in csharp. There is a community version of a mapping library that will map from native object types to Document type. It’s not complete but a good starting point- contributions welcome.