inrob
inrob

Reputation: 5089

how to store json in database

Is this better

{"details":{"number":"8","date":"29/06/2015","due_date":"06/07/2015"},

or this one:

%7B%22details%22%3A%7B%22number%22%3A%228%22%2C%22date%22%3A%2229%2F06%2F2015%22%2C%22due_date%22%3A%2206%2F07%2F2015%22

to store in a database?

Thank you.

Upvotes: 0

Views: 326

Answers (2)

Barny
Barny

Reputation: 1845

To answer your question, the first choice, because you can read it much easier, if you look for errors.

To go a little bit further. If you need to work with json structured data, think about using an OR mapper to safe the values of number, date anddue_datein separate columns in a table calleddetails`.

Upvotes: 0

tadman
tadman

Reputation: 211540

URI encoding values is completely pointless. Just store it as a JSON string with no encoding whatsoever, as JSON is already an encoding format.

URI encoding should be only for URIs. It has no other applicability. If you do need to encode, for whatever reason, use something standard like Base64.

Remember that you'll want to keep values like this as readable as possible, not scramble them arbitrarily.

Upvotes: 1

Related Questions