Can't parse JSON passed in metadata?

(Abhishek Madan) #1

Hi there,

I am hitting wit.ai via HTTP, and then passing the extracted entities as metadata to another flow. This JSON is what I send under the name “ent”, for example:

{
  "antinational": [
    {
      "confidence": 0.9977477113031028,
      "type": "value",
      "value": "beef"
    }
  ],
  "sentiment": [
    {
      "confidence": 0.6229497315269715,
      "value": "positive"
    }
  ],
  "intent": [
    {
      "confidence": 0.6366257572694627,
      "value": "anti"
    }
  ]
}

Now my next flow should be able access different parts of this JSON using the data output format… but it (the flow) is unable to.

For example, if I get the bot to post {{bot_new_message.metadata__ent}}, it works. But if I try to get it to post {{bot_new_message.metadata__ent__intent}} or {{bot_new_message.metadata__ent__intent__0__value}}, it does not work.

Am I missing something? Or is this a data format problem?

Thanks,
Abhishek

Using JSON data in a previous flow
(John Jackson) #2

The problem here is that when you pass all that JSON into a single metadata__ent, it’s treated as a string so you can’t use data outputs on it.

The solution is to pull the values you want out of the JSON and send those as metadata fields.

For example, set sentiment metadata to webhook.data__sentiment, or set antinational to webhook.data__antinational__0__value, etc…

Then in your next flow, you can reference them with {{bot_new_message.metadata__sentiment}} and {{bot_new_message.metadata__antinational}}.

1 Like
(Abhishek Madan) #3

Hi John, thanks for the reply.

Yeah I thought it was being passed as a string. I was doing what you are talking about, i.e. passing each value as a separate meta name in the metadata. But I was wondering if that’s a work around or the actual method.

Great job on FlowXO, the product itself is nice and powerful.

Cheers

(John Jackson) #4

Glad you like the product, good to have you on board :+1:

1 Like
(Enchiridion) #5

I’d also really like to see an option to pass JSON objects as metadata and retrieve them as objects later.

I’m trying to do nearly the same thing using DialogFlow, however creating individual meta fields for each value isn’t practical, it’s also slow, tedious, and doesn’t work well with variable data like arrays. (I’ve 20+ values I want to pass)

1 Like
#6

Hi @Enchiridion,

you should try with Code action:

  1. create code action to execute a JSON.stringify
  2. pass to your meta the result of previous action
  3. create code action to execute JSON.parse
  4. read the result of previous action
(Karen Barker) #7

@Enchiridion

When you pass the JSON object into a single metadata object it is treated as a string automatically. As @CaosMkt then states you could use the code function to transform the string back into objects via the JSON.parse function :thumbsup:

1 Like