1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Google_Service_SheetsのInvalid JSON Payloadエラーの解消

Posted at

自分用のメモです。。。。

  • やりたいこと

    • DBのユーザ情報をJSON形式にしてスプシに出力したい
    • revolution/laravel-google-sheetsのGoogle_Service_Sheetsを利用してスプシにデータを送信
  • エラー内容

    {
      "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Unknown name \"0\" at 'data.values[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"1\" at 'data.values[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"2\" at 'data.values[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"4\" at 'data.values[0]': Cannot find field.",
        "errors": [
          {
            "message": "Invalid JSON payload received. Unknown name \"0\" at 'data.values[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"1\" at 'data.values[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"2\" at 'data.values[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"4\" at 'data.values[0]': Cannot find field.",
            "reason": "invalid"
          }
        ],
        "status": "INVALID_ARGUMENT",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.BadRequest",
            "fieldViolations": [
              {
                "field": "data.values[0]",
                "description": "Invalid JSON payload received. Unknown name \"0\" at 'data.values[0]': Cannot find field."
              }
            ]
          }
        ]
      }
    }
    
  • 調査

    • encodeが違う説?

      ⇨utf8にencodeしても解決せず

    • content-typeをapplication/jsonにしないといけない?

      ⇨googleAPIが自動でやってくれてるみたい。オプションで指定も実装されてない。

    • nullをそのままJSONにしようとしてる?

      ⇨これでした。

  • 原因

    • nullをそのままJSONとして出力してる
  • 解決法

    • array_map等でnullは空文字に変換
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?