hi everyone - I’m wondering if someone can help me...
# community-help
a
hi everyone - I’m wondering if someone can help me understand a problem I’m running into trying to create collections with a schema which has
object
as the type on a field. I’m using typesense 0.24 on docker. even when I try copying and pasting the second`curl` example, the server errors and tells me I have “bad json”.
j
Could you adapt this gist, to replicate the error you’re seeing, so I can try it out locally?
a
let me take a look and see what I can do. one moment please simple smile
👍 1
oh this is interesting - when I try the first example on the docs page, with the
auto
indexed field, the collection is created successfully
j
Looks like there’s a typo in the docs. The last trailing comma after the array of fields is what’s causing the Bad JSON error
I’ll fix the docs
1
This should work
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": "docs",
        "enable_nested_fields": true,
        "fields": [
          {"name": "person", "type": "object"},
          {"name": "details", "type": "object[]"}
        ]
      }'
a
ah ok let me try that and then I’ll try my own project again. perhaps I missed a comma or something
j
The docs have an extra comma after
"object[]"},
, which is wrong
a
ok yes, that worked. one moment while I check the schema for my project…
oh no…. I’m feeling really silly… I wrote the schema in a
ts
file. I just have a habit of adding trailing commas to objects. that must be messing up the JSON object sent to the server. I’ll try removing them and see what happens
j
I’ve done this too 🙂
Sadly the JSON spec doesn’t allow trailing commas, even though Typescript, ECMAscript spec allow for it. So JSON parsers are strict about it
a
yeah and I also forgot about using double quotes instead of single quotes… habit
😄 1
well the collection got created and then I got a new kind of error. so that’s progress!
fwiw I’m using a proxy API to create collections, so there’s likely a problem with that
j
Btw, this is only an issue if you use curl. If you’re using the JS/TS client library, you can just pass in a JS object and the library will take care of converting it to JSON
a
ah right so my thing is a little different. I’m building a WP plugin which is passing the data through a nextJS proxy to the typesense server. it’s a little roundabout, but it’ll help with my situation and security. I think…
this is weird…. the JS client says the collection got created, but it also can’t be found…. I’ll keep working on it. it must be something I did
j
If you’re trying to read a collection right after it was created in successive method calls, you might see eventual consistency issues. Since it takes about a second for the collection to be available in memory for a get / search call
a
hm ok that’s good to know. I’ll check that out too. thanks for your help!
👍 1
well in the end it turns out I had one last problem that I’d overlooked. at one point, one of the fields was typed with a string and I’d set
sort
to true. I had accidentally changed the type to
object
but overlooked removing the
sort
property
👍 1