Detect JSON subtypes and JSON.parse() before returning.
#106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new potentially backwards-incompatible update: for columns that are the return values of JSON functions, it'll
JSON.parse()the text value and return list + objects instead of serialized JSON text.When using SQLite's builtin JSON functions, SQLite will give JSON values a special "subtype" value. We can use this "JSON subtype" to detect if a value is valid JSON. If so, we can parse the text string before returning the values back to the user.
An example:
This also works for all the other JSON builtin functions, including
json(),json_each(),json_tree(), and more. Other SQLite extensions can also use the JSON subtype convention in their own custom functions.Potentially backwards incompatible
Before, these functions would just return a string, and users would probably
JSON.parse()it themselves. But now, it can possibly return arrays, objects, decoded JSON strings and numbers, etc. Because of that, I think merging this PR as-is would be a major version bump (well, minor since it's pre-v1)However, we could also add a new database-level setting to make this new behavior opt-in. Maybe something like
db.enableJsonDeserializing(true)or something in the constructor. Happy to include if you think it's best!