向IBM Watson Discovery上传JSON报错:不支持顶级数组格式求助
Hey there, let's tackle that 400 error you're hitting when uploading your table data to Watson Discovery. The core issue here is straightforward: Watson Discovery doesn't accept JSON files that start with a top-level array ([ ... ]). It requires your data to be wrapped in a top-level object ({ ... }) instead.
Below are the supported formats you can use to structure your table-like data correctly:
1. Wrap Your Row Array in a Top-Level Object (Simplest Fix)
Take your existing array of row objects and nest it under a descriptive key (like rows, table_data, etc.). This preserves your original row structure while meeting Discovery's requirements. Example:
{ "table_data": [ { "employee_id": 101, "name": "Priya Mehta", "role": "Data Analyst", "location": "Bangalore" }, { "employee_id": 102, "name": "Raj Patel", "role": "Software Engineer", "location": "Mumbai" } ] }
2. Schema-Aware Structure (For Better Indexing & Querying)
If you want Discovery to recognize your table's structure more explicitly (helpful for later filtering/querying), you can separate column definitions from row data:
{ "table_schema": { "columns": ["employee_id", "name", "role", "location"], "column_types": ["integer", "string", "string", "string"] }, "table_rows": [ [101, "Priya Mehta", "Data Analyst", "Bangalore"], [102, "Raj Patel", "Software Engineer", "Mumbai"] ] }
Quick Rules to Follow
- No top-level arrays: Always start your JSON with
{and wrap all data inside this object. - Consistent keys: If using row objects, ensure every row has the same set of keys (columns) to avoid indexing inconsistencies.
- Validate syntax: Double-check your JSON with a linter before uploading—invalid syntax will also trigger errors.
Once you adjust your JSON to fit one of these formats, the 400 error should disappear, and Discovery will process your table data smoothly.
内容的提问来源于stack exchange,提问作者SurjayanGhosh

