Reputation: 411
I am trying with no success to insert a byte array in a postgresql json type as one of the json columns. is it possible? does anyone have an example?
Upvotes: 1
Views: 4898
Reputation: 26464
You can't, at least natively. JSON only allows 3 basic primative data types: number, string, and boolean. Everything else must be serialized to a string or number.
This means that you have three basic options:
Serialize to hexadecimal. The advantage is that it becomes easy to turn into a bytea in PostgreSQL if you need it.
Serialize to base64. The advantage here is that it uses up less space.
Serialize to a number array. This is not preferred in my view since it is hard to constrain each number to between 0 and 255.
Upvotes: 1