From e0098f35e93604417f5b30a3371d1f6a649c54f9 Mon Sep 17 00:00:00 2001 From: Dustin Byrne Date: Wed, 7 Oct 2026 15:22:42 -0400 Subject: [PATCH] fix(flags): support JSON 3 response parsing --- .changeset/json3-response-parsing.md | 6 ++++++ lib/posthog/feature_flags.rb | 2 +- spec/posthog/flags_spec.rb | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/json3-response-parsing.md diff --git a/.changeset/json3-response-parsing.md b/.changeset/json3-response-parsing.md new file mode 100644 index 0000000..1b5d91a --- /dev/null +++ b/.changeset/json3-response-parsing.md @@ -0,0 +1,6 @@ +--- +"posthog-ruby": patch +"posthog-rails": patch +--- + +Fix feature flag and remote config response parsing with JSON 3, restoring remote flag evaluation and local definition loading. diff --git a/lib/posthog/feature_flags.rb b/lib/posthog/feature_flags.rb index f56ed91..97592cf 100644 --- a/lib/posthog/feature_flags.rb +++ b/lib/posthog/feature_flags.rb @@ -1477,7 +1477,7 @@ def _request(uri, request_object, timeout = nil, include_etag: false, retry_stat # Parse response body to hash begin - response = JSON.parse(res.body, { symbolize_names: true }) + response = JSON.parse(res.body, symbolize_names: true) # Only add status (and etag if requested) if response is a hash extra_fields = { status: status_code } extra_fields[:etag] = etag if include_etag diff --git a/spec/posthog/flags_spec.rb b/spec/posthog/flags_spec.rb index d0f3408..98c2ab9 100644 --- a/spec/posthog/flags_spec.rb +++ b/spec/posthog/flags_spec.rb @@ -491,6 +491,14 @@ module PostHog JSON.parse(File.read(File.join(__dir__, 'fixtures', 'test-flags-v4.json')), symbolize_names: true) end describe '#get_feature_flag' do + it 'parses flag responses with keyword JSON options' do + body = { featureFlags: { 'enabled-flag' => true }, featureFlagPayloads: {} }.to_json + stub_request(:post, flags_endpoint).to_return(status: 200, body: body) + expect(JSON).to receive(:parse).with(body, symbolize_names: true).and_call_original + + expect(client.get_feature_flag('enabled-flag', 'test-distinct-id')).to eq(true) + end + it 'calls the $feature_flag_called event with additional properties' do stub_request(:post, flags_endpoint) .to_return(status: 200, body: flags_v4_response.to_json)