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

2.3.1 JSON no longer escaped. #157

Closed
zambetpentru opened this issue Mar 29, 2021 · 5 comments
Closed

2.3.1 JSON no longer escaped. #157

zambetpentru opened this issue Mar 29, 2021 · 5 comments

Comments

@zambetpentru
Copy link

Hi,

I just upgraded to 2.3.1 and the following query no longer returns JSON escaped

Select array_to_json(array_agg(row_to_json(A))) from (SELECT tablekey, tablename, ClientKey, CreatedDate, tableID
FROM public.table
      ) A

Before with 2.3.0:
[{"tablekey":1,"tablename":"Collection 1","clientkey":1,"createddate":"2020-02-05T00:00:00","tableID":"5f2134234q2342342324"}]

Now with 2.3.1:
[{tablekey: 1, tablename: Collection 1, clientkey: 1, createddate: 2020-02-05T00:00:00, tableID: 5f2134234q2342342324}]

Have you any ideas if there's something I need to change on my end or is it a bug?

@isoos
Copy link
Collaborator

isoos commented Mar 29, 2021

Please follow the repository/homepage url of the package, 2.3.1 is now published from a fork. It did have a change that has an effect on this behaviour: isoos/postgresql-dart#3

I'm not sure if the new behaviour is a bug, or a bugfix though. It kind of makes sense either way...

@zambetpentru
Copy link
Author

Hi, thanks for your reply. I think it's a bug as the response from any PostGreSQL client is as it was with 2.3.0 and now the output isn't valid JSON any more.

I'm a bit new to GitHub so what's the best way to raise this?

@isoos
Copy link
Collaborator

isoos commented Mar 29, 2021

I think the output is now a Map (which can be converted to JSON string via json.encode()). Having a Map there seems to be better, as it returns a parsed structure instead of a string that you need to parse...

@zambetpentru
Copy link
Author

Hi @isoos, thanks so much for coming back to me with a solution - indeed if I update my app to wrap jsonEncode around the result from the query I get a proper JSON object again. :-)

In my case I'm using the database to generate JSON I can pass directly to my API.

I would say it's not a desirable default behaviour (but useful as an option) as my query above gives a single cell result string but now in 2.3.1 the package is deciding to try and parse it. I can also seem to override it with the following query:

 Select CONCAT('', array_to_json(array_agg(row_to_json(A)))) from (SELECT Publication_Key, Publication_Name, Client_Key, Created_Date, Publication_ID
FROM public.Publications
      ) A

If you decide to keep it as is it looks like you should rename the version 2.3.1 to 3.0.0 as it is a breaking change in line with the Dart Pub versioning: https://semver.org/spec/v2.0.0-rc.1.html

@isoos
Copy link
Collaborator

isoos commented Mar 30, 2021

Hm, two additional things we can consider:

  • if the client gets a String, it could be better for the performance to leave it as-is, for cases like @zambetpentru has, however
  • if other platform clients get a parsed value in such cases, we should probably follow. Any insight on this?

/cc @schultek the author of the given change in case there is more to it.

@zambetpentru zambetpentru closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2024
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

No branches or pull requests

2 participants