Skip to content

[Bug] JSON payload decoding raises ArgumentError with json 3.x (JSON.parse options are keyword-only) #595

Open

Description

@bray

What are you really trying to do?

Decode JSON payloads (and failures with encode_common_attributes: true) with json 3.x installed.

Describe the bug

json 3.0 changed JSON.parse to take its options as keyword arguments only:

def parse(source, on_load: nil, object_class: nil, array_class: nil, **options)

Temporalio::Converters::PayloadConverter::JSONPlain#from_payload passes them as a positional hash:

JSON.parse(payload.data, @parse_options)

(temporalio/lib/temporalio/converters/payload_converter/json_plain.rb, both branches, still present on main.)

So with json >= 3.0 every JSON payload decode raises:

ArgumentError: wrong number of arguments (given 2, expected 1)
  json-3.0.2/lib/json/common.rb:296:in `parse'
  temporalio-1.9.0/lib/temporalio/converters/payload_converter/json_plain.rb:55:in `from_payload'
  temporalio-1.9.0/lib/temporalio/converters/payload_converter/composite.rb:66:in `from_payload'
  temporalio-1.9.0/lib/temporalio/converters/data_converter.rb:90:in `from_payloads'

A quieter side effect: FailureConverter#from_failure ignores errors while decoding encoded_attributes, so with encode_common_attributes: true the decoded error's message is left as "Encoded failure" and nothing is raised.

Encoding is unaffected: JSON.generate(value, @generate_options) still accepts a positional hash in json 3.

temporalio.gemspec doesn't constrain json, so a fresh resolve picks up 3.x.

Minimal Reproduction

# Gemfile: gem "temporalio", "1.9.0"; gem "json", "3.0.2"
require "temporalio/converters"

dc = Temporalio::Converters::DataConverter.default
dc.from_payloads(dc.to_payloads([{ "a" => 1 }]))
# => ArgumentError: wrong number of arguments (given 2, expected 1)

Passes with json 2.21.2.

Suggested fix

Splat the options so it works on both json 2.x and 3.x:

JSON.parse(payload.data, **@parse_options)

and/or add json to the gemspec with a lower bound that supports keyword options.

Environment/Versions

  • temporalio 1.9.0 (also present on main)
  • json 3.0.2
  • Ruby 3.2, 3.3, 3.4 (reproduced on all three in CI; locally on 3.3.4, arm64-darwin)

Additional context

Workaround: pin gem "json", "< 3" in the application's Gemfile.

Activity

  1. deepanshupal commented on Oct 5, 2026

    @deepanshupal

    Confirmed on json 3.0.2 / Ruby 3.3. Splatting alone (**@parse_options) won't fix the default converter though: json 3.0 removed create_additions entirely, so JSON.parse(data, **{create_additions: true}) now raises 'unknown keyword: create_additions'. The default parse_options and the README's json_create / create_id example both depend on that option. Before touching code: do you want the default to drop create_additions when json >= 3, keep it behind a version check, or constrain json < 3 in the gemspec for now? Happy to put up a PR with tests once you pick a direction.

  2. bray commented on Oct 5, 2026

    @bray
    Author

    Confirmed on json 3.0.2 / Ruby 3.3. Splatting alone (**@parse_options) won't fix the default converter though: json 3.0 removed create_additions entirely, so JSON.parse(data, **{create_additions: true}) now raises 'unknown keyword: create_additions'. The default parse_options and the README's json_create / create_id example both depend on that option. Before touching code: do you want the default to drop create_additions when json >= 3, keep it behind a version check, or constrain json < 3 in the gemspec for now? Happy to put up a PR with tests once you pick a direction.

    Thanks for confirming, and for spotting the create_additions removal. I hit the positional-args error first and didn't get past it.

    From the consumer side, a gemspec constraint of json < 3 would be the quickest fix. Right now Bundler resolves temporalio with json 3, and every JSON payload decode fails at runtime. A constraint turns that into a resolve-time conflict, which is much easier to diagnose.

    A proper fix can then come later without blocking anyone. It'll need a call on what replaces create_additions / json_create, since json 3 dropped that object-revival feature entirely, not just the option.

    Workaround for anyone landing here: add gem "json", "< 3" to your app's Gemfile.

  3. chris-olszewski commented on Oct 7, 2026

    @chris-olszewski
    Member

    Limited the json dependency for the time being. With an on_load hook we can achieve recreate some of the create_additions behavior most of the time, but the edge cases where we wouldn't match the behavior would lead to unexpected objects returned from activities etc.

  4. deepanshupal commented on Oct 16, 2026

    @deepanshupal

    Thanks, the json pin in #607 covers it for me. I won't send a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions