Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse arrays: json[], uuid[] #456

Merged
merged 2 commits into from
Oct 18, 2013
Merged

Parse arrays: json[], uuid[] #456

merged 2 commits into from
Oct 18, 2013

Conversation

albert-lacki
Copy link

I've added parsing of two additional types json[] and uuid[]. I'll be happy if you could merge it.

@brianc
Copy link
Owner

brianc commented Oct 18, 2013

Awesome, thanks.

brianc added a commit that referenced this pull request Oct 18, 2013
Parse arrays: json[], uuid[]
@brianc brianc merged commit 786f5e6 into brianc:master Oct 18, 2013
@demisx
Copy link

demisx commented Feb 25, 2015

Guys, I have a jsonb[]type column photos in my Postgres 9.4 table. My ORM is Bookshelf that uses pg as a client. When I fetch records the API responds with the array in this format:

{"{\"url\": \"https://example.com/photo1.jpg\"}","{\"url\": \"https://example.com/photo2.jpg\"}"}

As you can see, it is still in Postgres specific format. Should the conversion to a conventional JSON array (e.g. [{...},{...}] be handled by the pg parser or am I wrong? I am posting under this issue, since I think it may be related to this parser. Please advise. Thank you.

@brianc
Copy link
Owner

brianc commented Feb 25, 2015

I think it should probably convert to a json structure, but I'm not sure
what additional bits of encoding are housed within JSONB that aren't
supported by a standard JSON.parse style call? Is there a good JSONB
library for node we could add to node-pg-types

On Wed, Feb 25, 2015 at 1:52 AM, Dmitri Moore notifications@github.com
wrote:

Guys, I have a jsonb[]type column photos in my Postgres 9.4 table. My ORM
is Bookshelf that uses pg as a client. When I fetch records the API
responds with the array in this format:

{"{"url": "https://example.com/photo1.jpg\"}","{\"url\": "https://example.com/photo2.jpg\"}"}

As you can see, it is still in Postgres specific format. Should the
conversion to a conventional JSON array (e.g. [{...},{...}] be handled by
the pg parser or am I wrong? I am posting under this issue, since I think
it may be related to this parser. Please advise. Thank you.


Reply to this email directly or view it on GitHub
#456 (comment).

@demisx
Copy link

demisx commented Feb 25, 2015

Thank you for the prompt response. I believe this issue applies to both, JSON[ ] and JSONB[ ] array parsing. I am not aware of any good libraries for this and googling didn't reveal much besides just some Ruby and C libs like this one: https://code.google.com/p/pg-to-json-serializer/. Not sure if I was looking for the right stuff, though, since this is not yet my area of expertise.

Shall I create a new issue to track this effort?

@bendrucker
Copy link
Contributor

There's no issue with parsing jsonb with JSON.parse that I know of. The main upside is in storing data in a binary, typed format as opposed to just a dumb string.

Opened brianc/node-pg-types#21

@demisx
Copy link

demisx commented Feb 25, 2015

@bendrucker You are correct. I don't see any issues with parsing if I define the column as json[] instead of jsonb[]. My previous assumption about both was incorrect.

@bendrucker
Copy link
Contributor

If you want a good blog post from the guy who reviewed jsonb, check this out:

http://pgeoghegan.blogspot.com/2014/03/what-i-think-of-jsonb.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants