JSON File Upload Fails

I tried uploading a sample JSON file into Vectara using the dashboard but it kept throwing errors one after the other. Here is the final JSON format I arrived at before resorting to asking for help on this forum.

I’m getting 400 error code saying:
Invalid JSON: Cannot find field: restaurantName in message com.vectara.indexing.Section

Here is my filter attribute screenshot:

I reviewed this documentation section which showed how the document object needs to be formatted and that’s what I did, but still throws an error.

{
  "documentId": "BurgersDoc1",
  "title": "Top Burgers in Philly",
  "section": [
    {
      "restaurantName": "Fountain Porter",
      "dishNames": [
        "cheeseburger"
      ],
      "description": "some description",
      "address": {
        "address": "1601 S 10th Street",
        "city": "Philadelphia",
        "state": "PA",
        "zipCode": "19148"
      },
      "formattedAddress": "1601 S 10th Street, Philadelphia, PA 19148"
    },
    {
      "restaurantName": "Butcher & Singer",
      "dishNames": [
        "burger"
      ],
      "description": "another description",
      "address": {
        "address": "1500 Walnut Street",
        "city": "Philadelphia",
        "state": "PA", 
        "zipCode": "19102"
      },
      "formattedAddress": "1500 Walnut Street, Philadelphia, PA 19102"
    },
    {
      "restaurantName": "Standard Tap",
      "dishNames": [
        "burger"
      ],
      "description": "hello world.",
      "address": {
        "address": "901 N 2nd Street",
        "city": "Philadelphia",
        "state": "PA",
        "zipCode": "19123"
      },
      "formattedAddress": "901 N 2nd Street, Philadelphia, PA 19123"
    },
    {
      "restaurantName": "Pub & Kitchen",
      "dishNames": [
        "burger"
      ],
      "description": "goodbye world",
      "address": {
        "address": "1946 Lombard Street",
        "city": "Philadelphia", 
        "state": "PA",
        "zipCode": "19146"
      },
      "formattedAddress": "1946 Lombard Street, Philadelphia, PA 19146"
    },
    {
      "restaurantName": "Rouge",
      "dishNames": [
        "burger"
      ],
      "description": "final world.",
      "address": {
        "address": "205 South 18th Street",
        "city": "Philadelphia",
        "state": "PA",
        "zipCode": "19103"
      },
      "formattedAddress": "205 South 18th Street, Philadelphia, PA 19103"
    }      
  ]
}
    

Welcome to Vectara forum Mohammad.

As per documentation at Format Files for Upload | Vectara Docs, the expected JSON format has to follow the “Document” structure outlined in the proto here: protos/indexing.proto at main · vectara/protos · GitHub

In the “section” array, each element has to follow this format: protos/indexing.proto at main · vectara/protos · GitHub
Fields such as “restaurantName” do not exist in the “section” message, hence the error.
Which fields do you want to make searchable? Those need to be added to the “title” or “text” fields of “section”. If you want to add metadata, that should be added to the “metadata” field.

Please let us know if you’re still facing issues.

Hi Tallat,

Thank you for your support. I didn’t initially understand that the proto needed to be followed strictly in order for the JSON file to be accepted. I followed the format strictly and it worked - thanks!

For users who might be scratching their heads on the JSON topic reading this, here is a summary for you:

  • Each JSON file is a document
  • Each document requires document level and section level fields to be defined/included
  • You can nest more sections within “section”
  • The mandatory fields on the document level are: document_id, title, and section. I haven’t tried uploading an empty section array but I assume it’s required. It would be useless not to include a section array.
  • The mandatory field on the section level is just “text”
  • Your filter attributes go in the metadata_json string. Use a JSON to string converter to add your string here. metadata_json can be added on a document, section, and subsection levels.

Good luck!

1 Like