Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Kilowhisky opened this issue Apr 30, 2024 · 4 comments
Closed

Comments

@Kilowhisky
Copy link
Contributor

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...

@Kilowhisky
Copy link
Contributor Author

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?

@Kilowhisky
Copy link
Contributor Author

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

@Kilowhisky
Copy link
Contributor Author

Kilowhisky commented May 1, 2024

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

Tile38Error: Unexpected token _ in JSON at position 11948

image

tidwall added a commit that referenced this issue May 4, 2024
This commit fixes an issue where fields with floating points
that have zero prefixes and underscores are being parsed as
numbers.

Now those are treated as string values.

See #736
@tidwall
Copy link
Owner

tidwall commented May 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants