ijprest / keyboard-layout-editor

Web application to enable the design & editing of keyboard layouts
http://www.keyboard-layout-editor.com/
Other
1.32k stars 246 forks source link

KLE needs a JSON schema #321

Open Joebeazelman opened 2 years ago

Joebeazelman commented 2 years ago

I'm trying to implement a small program to read KLE JSON files. It would be incredibly useful if a JSON schema describing the structure of the JSON objects existed. JSON schema lets you generate the boilerplate object types as code. This would make it much easier for developers to integrate with KLE. QMK has one, but I wasn't able to get anywhere with it and the layout seemed incomplete.

ijprest commented 2 years ago

It's not a schema, but if you want to read/parse KLE's files, check out: https://github.com/ijprest/kle-serial

Joebeazelman commented 2 years ago

Perhaps I should clarify that I am not using JS nor TypeScript. I was able to create a schema from the class definitions you provided in kle-serial. I then used it to generate a C# class for deserializing the keyboard objects. It doesn't, however, work for the raw files downloaded from the KLE site.

Fortunately, I was able to find kle-serial, which converts the files into a more readable format. The converter works almost flawlessly, but I encountered an issue where the first key only has 5 elements in the array field of the first key:

https://github.com/adamws/kle-serial/issues/23#issue-1424555418

I can't tell if the source of the issue is from the KLE source file or from the conversion tool.

It would be great if users could download the normalized json format without having to go through a conversion process. I'm contributing the jsonschema file in zip format. Please feel free to do as you like.

KLE.jsonschema.zip

adamws commented 1 year ago

I think that this is expected, labels are split with "\n" https://github.com/ijprest/kle-serial/blob/master/index.ts#L119 (and then reordered) so you won't get constant length labels array after conversion. As far as my tool considered, I don't see an issue.