You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Adyen Web SDK初始化异常:JSON格式错误排查求助

Fixing "JSON passed to chckt.checkout was not properly formatted" Error in Adyen Web SDK

Let's troubleshoot this issue step by step—based on the error message and your test cases, the core problem lies in how the paymentSession is being handled before passing it to the SDK.

Why You're Seeing This Error

The error explicitly states typeof data: boolean, which means the SDK is receiving a boolean value instead of the expected valid JSON object for paymentSession. Even though you mentioned it's a long string from Postman, there's a high chance either:

  1. The raw string isn't being parsed into a JSON object before passing it to chckt.checkout(), or
  2. The string itself is invalid JSON (e.g., missing quotes, extra whitespace, or corrupted during copy-paste), causing the SDK's internal parsing to fail and fall back to an unexpected boolean value.

Step-by-Step Fixes

1. Explicitly Parse the paymentSession String

Adyen's Web SDK expects the paymentSession parameter to be a parsed JSON object, not a raw string. Here's how to adjust your code:

// First, confirm the type and content of your paymentSession
console.log("Payment session type:", typeof paymentSession);
console.log("Payment session content snippet:", paymentSession.slice(0, 50));

// Wrap parsing in try/catch to catch invalid JSON issues
try {
  const parsedSession = JSON.parse(paymentSession);
  // Pass the parsed object to the SDK instead of the raw string
  var checkout = chckt.checkout(parsedSession, '#payment-container', sdkConfigObj);
} catch (parseError) {
  console.error("Failed to parse paymentSession:", parseError);
  // If this throws, your string is invalid—check the Postman response again
}

2. Validate the Raw paymentSession String

If the JSON.parse() call fails, double-check these details:

  • Did you copy the full response from Postman? Partial copies (e.g., missing the opening { or closing }) break JSON validity instantly.
  • Are there extra characters (leading/trailing spaces, newlines, or accidental escape sequences) that snuck in during copy-paste? Use a JSON validator tool to paste the string and confirm it's well-formed.
  • Is the Postman response itself valid? Inspect the "Body" tab in Postman to ensure the API isn't returning malformed JSON.

3. Rule Out Accidental Variable Modification

Make sure no other code is altering the paymentSession variable before you pass it to the SDK. For example, logic like if (paymentSession) { ... } could implicitly convert the string to a boolean if the string is empty or incorrectly evaluated, leading to this exact error.

Additional Context

Your test results (getting specific errors for invalid inputs like numbers or non-existent DOM nodes) confirm the SDK is working as expected for bad inputs. The fact that you're hitting a JSON formatting error with your "correct" input means the issue is definitely tied to how paymentSession is structured or passed.


内容的提问来源于stack exchange,提问作者Radu Florin Dunărențu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:18:13