tidwall / tile38

Real-time Geospatial and Geofencing

Home Page:https://tile38.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid JSON created when setting a field to a string value like '000296'.

Kilowhisky opened this issue · comments

Describe the bug
When the OUTPUT is set to JSON and a field was set to a string value like '000296'. The tile38 serializer will automatically convert the field into a number and try and output 000296. This is invalid json though because you cannot have leading 0's in numbers according to the JSON spec. This creates errors with many of the client libraries that utilize JSON.parse() (i'm using tile38-ts).

To Reproduce

  1. Set output to JSON
  2. Set a field to a value of '000296'
  3. Get the record
  4. See that it converted the field to a numerical field with leading zeros.

Expected behavior
Strip leading zeros when converting it to a number?

Logs

Tile38Error: Unexpected number in JSON at position 14454
image

Operating System (please complete the following information):

  • OS: AWS ECS
  • CPU: ???
  • Version: 1.30.2
  • Container: ECS

Additional context
I can fix in insertion handler, but invalid JSON should not be created either way...

So this is tied to this issue: #719
Turns out, that field is supposed to be "vehicle name". The vehicle just happens to be called '000296'...

So i'm not sure how to fix this besides moving the "vehicle name" property to under the "properties" object. But i'm not sure if i can do that as that object is currently inserted as a POINT and performance is critical.

Thoughts?

I'm just going to prepend the field value with vn:<name>. Its a hack, but it works.

Turns out _ is also a valid number character for Go but not for JSON....

Tile38Error: Unexpected token _ in JSON at position 11948

image

I just pushed an update that will ensure that a numeric field value conforms to JSON.