Hello, I have a problem when I try to create a col...
# community-help
c
Hello, I have a problem when I try to create a collection the following error is returned: {"message": "Bad JSON."} Yet I made a copy and paste of the official Typesense guide.
curl "http://workmetadata.francecentral.cloudapp.azure.com:5005/collections" -X POST -H "Content-Type: application/json" -H "X-TYPESENSE-API-KEY: keyhdh" -d collection.json
Here is the command line I run and my file collection.json
k
👋 Can you please post the collection.json as text here? Let me try, maybe there are some non-visible bad characters that's not valid json.
c
Copy code
{
  "name": "books",
  "fields": [
    {
      "name": "title",
      "type": "string"
    },
    {
      "name": "authors",
      "type": "string[]",
      "facet": true
    },
    {
      "name": "publication_year",
      "type": "int32",
      "facet": true
    },
    {
      "name": "ratings_count",
      "type": "int32"
    },
    {
      "name": "average_rating",
      "type": "float"
    }
  ],
  "default_sorting_field": "ratings_count"
}
k
This works for me locally:
Copy code
curl -k "<http://localhost:8108/collections>" -X POST -H "Content-Type: application/json" \
      -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
    "name": "books",
    "fields": [
      {"name": "title", "type": "string" },
      {"name": "authors", "type": "string[]", "facet": true },
      {"name": "publication_year", "type": "int32", "facet": true },
      {"name": "ratings_count", "type": "int32" },
      {"name": "average_rating", "type": "float" }
    ],
    "default_sorting_field": "ratings_count"
  }'
The guide uses inline JSON bodies like this and not
-d collection.json
-- if you can tell me where exactly in the guide we use this format, I can also check that.
c
I copy paste your command line and it works. Thank you very much
k
👍