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?
1 Answer
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.
1 Comment
Zeeshan Shamsuddeen
when you say JSON allows 3 data types, are you referring to the values in a JSON object?