JSON5 support
What is your use-case and why do you need this feature? It would be nice to have JSON5 support to serialize/deserialize configs and other data files that may be written/read by humans. It has quite useful features:
- No quotes for keys when they're not needed
- Multi-line strings
- Trailing comas
- Single- and Multi-line comments.
- and some more
Describe the solution you'd like Well, pretty much the same as for JSON but form JSON5. I don't know what else to say here. All details on the format are on json5.org
Side note: trailing commas and unquoted literals are now somewhat supported by isLenient = true setting
Side note: IntelliJ has native support (e.g. syntax highlighting) for Json5 (link), which would make this a cool feature for Android developers especially
now How is it going ?
I'm also interested in this. For now, I've converted an existing JSON5 Java library to Kotlin and added some Kotlinx Serialization interop, so it can convert to/from JSON5/JSON. Please let me know if it's useful, and you're able to help make it more stable (I haven't tested it significantly)
https://github.com/adamko-dev/json5-kotlin
Hi, any news about that ? Im trying to use json5, but it seems that kotlinx.serialization dont like comment
{
/*
* The day when players will be able to do damage to themselves. default -> 2
*/
"dayOfAuthorizationOfThePvP": 2,
/*
* The day when players can get into the nether. default -> 4
*/
"dayOfAuthorizationOfTheEntryInTheNether": 4,
/*
* If players can use enderpearl to assault bases or not
*/
"allowEnderPearlAssault": false
}
error
Caused by: java.lang.RuntimeException: kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 11: Expected semicolon ':', but had ' ' instead at path: $
JSON input: {
/*
* The day when players will b.....
at ch.skyfy.jsonconfig.example3.config.Configs.<clinit>(Configs.kt:25)
... 90 more
Caused by: kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 11: Expected semicolon ':', but had ' ' instead at path: $
I don't think we'll embed JSON5 standard into our implementation. Current policy for format requests is 'write your own 3rd party lib with dependency on the core'
I was faced with the need to deserialize JSON5 combined with a few additional requirements (such as full support for polymorphic types and error messages that can be exposed to the end user).
To meet these requirements, I created the json5k library. Feel free to take a look at it if you are in a similar situation.
Due to the fact that JSON5 is a superset of JSON, the library might also be suitable if you need to deserialize JSON files with trailing commas (#1812). In this case, however, you might be unable to reject inputs that violate other portions of the original JSON specification.
Thank you very much, I think that's what I need
Side note: trailing commas and unquoted literals are now somewhat supported by
isLenient = truesetting
For me trailing commas are throwing an error. What exactly does "somewhat" mean and is there a way to disable that check?
I tried out the json5k library and it seems to be great, but unfortunately it doesn't support iOS multiplatform targets.
@ubuntudroid I've rechecked now — no, there's no way to disable trailing comma check even in lenient mode
Alright, thanks for checking so quickly anyway! 🙏
I can't parse API of this site cuz this library doesn't support trailing comma: https://developers.home-assistant.io/docs/intent_conversation_api/#response_types