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

JSON5 support #797

Closed
acanthite1855 opened this issue Apr 11, 2020 · 14 comments
Closed

JSON5 support #797

acanthite1855 opened this issue Apr 11, 2020 · 14 comments

Comments

@acanthite1855
Copy link

acanthite1855 commented Apr 11, 2020

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

@sandwwraith
Copy link
Member

Side note: trailing commas and unquoted literals are now somewhat supported by isLenient = true setting

@MarcelReiter
Copy link

Side note: IntelliJ has native support (e.g. syntax highlighting) for Json5 (link), which would make this a cool feature for Android developers especially

@lisonge
Copy link

lisonge commented Dec 18, 2021

now How is it going ?

@aSemy
Copy link
Contributor

aSemy commented Dec 22, 2021

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

@AmibeSkyfy16
Copy link

AmibeSkyfy16 commented Jul 16, 2022

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: $

@sandwwraith
Copy link
Member

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'

@xn32
Copy link
Contributor

xn32 commented Sep 20, 2022

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.

@AmibeSkyfy16
Copy link

Thank you very much, I think that's what I need

@ubuntudroid
Copy link

ubuntudroid commented Feb 1, 2023

Side note: trailing commas and unquoted literals are now somewhat supported by isLenient = true setting

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.

@sandwwraith
Copy link
Member

@ubuntudroid I've rechecked now — no, there's no way to disable trailing comma check even in lenient mode

@ubuntudroid
Copy link

Alright, thanks for checking so quickly anyway! 🙏

@GazimSoliev
Copy link

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

sandwwraith added a commit that referenced this issue Oct 17, 2023
This is one of the popular community requests and one of the main reasons people ask for Json5 support.
Implementing this flag separately will allow alleviating large paint points quickly without a need to wait for full Json5 support.

Fixes #1812
Relates to: #797, #2221
sandwwraith added a commit that referenced this issue Oct 19, 2023
This is one of the popular community requests and one of the main reasons people ask for Json5 support.
Implementing this flag separately will allow for alleviating large paint points quickly without waiting for full Json5 support.

Fixes #1812
Relates to: #797, #2221
@sandwwraith sandwwraith self-assigned this Dec 18, 2023
sandwwraith added a commit that referenced this issue Mar 5, 2024
in C/Java style for both string and stream parser.

This flag together with allowTrailingCommas and isLenient will help
to cover most use-cases for Json5, for example, configuration files.

Fixes #2221
Fixes #797
@lisonge
Copy link

lisonge commented Aug 11, 2024

This parser still doesn't support single-quoted strings in JSON5

#2765

maybe it can be reopend

@sandwwraith
Copy link
Member

Yes, we decided not to support single/double quotes for now, this is something for future improvement if there is a demand for it.

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

No branches or pull requests

9 participants