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

Introduce JSON::Fragment #732

Merged
merged 1 commit into from
Jan 20, 2025
Merged

Introduce JSON::Fragment #732

merged 1 commit into from
Jan 20, 2025

Conversation

etiennebarrie
Copy link
Contributor

To combine JSON fragments to build a bigger JSON document, you can use JSON::Fragment:

posts_json = cache.fetch_multi(post_ids) do |post_id|
  JSON.generate(Post.find(post_id))
end
posts_json.map { |post_json| JSON::Fragment.new(post_json) }
JSON.generate({ posts: posts_json, count: posts_json.count })

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
@byroot byroot merged commit c31ba89 into ruby:master Jan 20, 2025
33 checks passed
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.

2 participants