Here I want to output json with dynamic group name rather than word group
@tickets.each do |group, v|
  json.group {
    json.array! v do |ticket|
      json.partial! 'tickets/ticket', ticket: ticket
    end}
end
Where @ticket is a hash like this
{a: [....], b: [.....]}
and I want output like this
{a: [
.....
],
b: [
....
]}
                Thanks to @AntarrByrd there is similar answer to this problem: JBuilder dynamic keys for model attributes
Using above logic I have solved this issue:
@tickets.each do |k, v|
    json.set! k do
      json.array!(v)do |ticket|
        json.partial! 'tickets/ticket', ticket: ticket
      end
    end
  end
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With