Code sample for Qna "Import from JSON"?

Hi there,
I’m trying to use the “Import from JSON” feature in the QnA manager. The subtitle in the Import JSON dialog is quite vague. It says:

JSON should be formatted “question,answer_type,answer,answer2,category”

This is quite vague and doesn’t look like JSON to me. I’ve tried throwing a few different variations of these fields into a JSON file but I keep getting unhelpful error messages when I try to import.

Does anyone have an example of a valid JSON file for import into QnA?

Looks like it’s expecting the same format of JSON as is created by the “Export to JSON” feature on the QnA page.

To botpress devs reading this: it would be helpful to update the description on the Import from JSON dialog to make it clear that’s what is needed.

It also seems that the “ID” property is required but will be ignored and replaced by a new unique ID.

Here’s a code snippet that seems to work:

[
  {
    "id": "ID0",
    "data": {
      "questions": {
        "en": [
          "Question?",
	  "Question variation?" 
        ]
      },
      "answers": {
        "en": [
          "Answer",
	  "Answer variation"
        ]
      },
      "redirectFlow": "",
      "redirectNode": "",
      "action": "text",
      "category": "global",
      "enabled": true
    }
  },
  {
    "id":"ID1",
    "data": {
      "questions": {
        "en": [
          "Question 2?",
          "Question 2 variation?"
        ]
      },
      "answers": {
        "en": [
          "Answer 2",
	  "Answer 2 variation"
        ]
      },
      "redirectFlow": "",
      "redirectNode": "",
      "action": "text",
      "category": "global",
      "enabled": true
    }
  }
]

Hi Nathanielgranor,

Thanks for the feedback.

By the way, we are also welcome to pull requests from the community, especially in pretty straightforward cases like this.

Kind Regards and happy bot building,
JB

1 Like