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

Jbuilder #merge! doesn't follow json.key_format! rule #473

Closed
aruprakshit opened this issue Jan 3, 2020 · 1 comment · Fixed by #486
Closed

Jbuilder #merge! doesn't follow json.key_format! rule #473

aruprakshit opened this issue Jan 3, 2020 · 1 comment · Fixed by #486

Comments

@aruprakshit
Copy link

I have in my partial:

json.key_format! camelize: :lower

json.credit_balance @user.available_credits
json.company_state @user.company_profile.state
json.subscription do
  json.merge! @user.subscription.to_h
end

But rendered json doesn't produced by following camelize: :lower rule.

{
  "creditBalance": 28,
  "companyState": "NJ",
  "subscription": {
    "active": true,
    "current_period_end": "03/02/2020"
  }
}

See current_period_end should be currentPeriodEnd.

I am using Rails 5.2.

blackjack26 added a commit to blackjack26/jbuilder that referenced this issue Apr 9, 2020
Converts the keys of all hashes within arrays and ones being merged in
to follow the specified key format.

Fixes rails#473
@dhh dhh closed this as completed in #486 Jan 22, 2021
dhh pushed a commit that referenced this issue Jan 22, 2021
Converts the keys of all hashes within arrays and ones being merged in
to follow the specified key format.

Fixes #473
@Deekor
Copy link

Deekor commented Jul 11, 2021

I'm on gem version 2.11.2 and still experiencing this issue.

  def as_json(options = nil)
    j = Jbuilder.new do |json|
      json.key_format! camelize: :lower
      json.merge! super.to_h
    end
    j.attributes!
  end

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 a pull request may close this issue.

2 participants