Reputation: 607
Trying to build a JSON string for use with a service and want to pass some of the JSON keys as variables.
I've tried:
def blah( field, value )
...
body = { request: { field.to_sym value } }
and
body = { request: { field.to_sym: value } }
but get errors in the console. What's the proper syntax here?
Thanks.
Upvotes: 1
Views: 404
Reputation: 434585
I'm guessing that you're looking for the hashrocket syntax:
body = { request: { field.to_sym => value } }
# -------------------------------^^
The JavaScript-style k: v
notation can only be used with a limited set of literal symbols.
Upvotes: 1