Zapier 发送 Python JSON 字典并跳过空值 [英] Zapier sending Python JSON dict and skipping null values

查看:54
本文介绍了Zapier 发送 Python JSON 字典并跳过空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 Limo 任何地方触发,我在我的 node.js 代码操作中获取值.假设我们从触发器中获得以下值:

From Limo anywhere trigger, I am getting the values in my node.js code action. Suppose we are getting following value from the trigger:

null,the four seasons hotel;

Zapier 仅发送代码中的四季酒店.Zapier 有没有办法获取 rawJSON 并在代码中解析它?

Zapier is sending only the four seasons hotel in the code. Is there a way in Zapier to get the rawJSON and parse it in the code?

我的代码:

    let rows = "";
    const totalRecords = firstNames.length;
    const toLocations = inputData.to_location.split(",");
    const firstNames = inputData.first_name.split(",");
    const lastNames = inputData.last_name.split(",");
    const pickupDates = inputData.pickup_date.split(",");
    const fromLocations = inputData.from_location.split(",");

    for(let i = 0; i < totalRecords; i++){
       rows += `${firstNames[i]} ${lastNames[i]} ${fromLocations[i]} ${toLocations[i]} ${pickupDates[i]}`;
       if(i !== (totalRecords - 1)){
          rows += ",";
       }
    }

    return {
       rows: rows
    };

推荐答案

以下是上述问题的复杂解决方案:

Following is the complex solution of the Above problem :

  1. 在 Zapier 中制作一个单独的Catch Raw Webhook".
  2. 使用上面 #1 中的 Webhook URL,并将其添加为现有 Limo 任意位置触发器上的 Webhook 操作.此 webhook 操作将在raw"参数下将 json 作为 post 发送.选择自定义请求则方法为POST,数据传递为yes.

  1. Make a separate "Catch Raw Webhook" in Zapier.
  2. Use the Webhook URL from #1 above and add it as a webhook action on existing Limo anywhere trigger. This webhook action will send json as post under "raw" parameter. Choose custom request then method will be POST, data pass through will be yes.

在 webhook 触发器之后添加一个代码动作来解析 Zapier 中的 Python 字典字符串:

Add a code action after webhook trigger to parse the Python Dictionary string in Zapier :

import json, ast
output = {'res': json.dumps(ast.literal_eval(input_data["raw"]))}

  1. 这将为您提供与 Javascript 兼容的正确 JSON,从这里您可以处理数据.

我不得不在 #3 中使用 python,因为原始 JSON 只与 Python 兼容,它看起来如下:

I had to use python in #3 because raw JSON was only compatible with Python and it looked like following :

{u'due_date': u'2019-03-22T00:00:00', u'terms': u'due_upon_receipt'}

这篇关于Zapier 发送 Python JSON 字典并跳过空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆