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

JSON Formatting can be improved #40

Closed
manurana opened this issue Jun 20, 2024 · 2 comments · Fixed by #78
Closed

JSON Formatting can be improved #40

manurana opened this issue Jun 20, 2024 · 2 comments · Fixed by #78

Comments

@manurana
Copy link

When you paste some JSON into the values editor, monaco editor formats it automatically. However, the formatting is not the best. I am attaching an example:
image

Here is the JSON I am using for the example, and how it should ideally be formatted

{
    "lastState": "*",
    "eventId": "EVT_SELECT_OPTION_MF_SHARES",
    "accountId": "57363",
    "httpEventId": null,
    "tenant_code": "KNAB"
}

I tried changing the default language for the Editor component in the Values Editor to json instead of typescript, but did not see any improvement.

@giacomocerquone
Copy link
Collaborator

giacomocerquone commented Aug 3, 2024

Setting either the language prop or the defaultLanguage one to json works on my local environment 🤷

The reason we can't set the language to json though, is that it will force users to always type the double quotes ("") on each property.
Setting the language to typescript instead doesn't work as expected because what we're looking at has a different meaning.
I mean, when you have a tsfile.ts on your editor and write something like this:

{
    "lastState": "*",
    "eventId": "EVT_SELECT_OPTION_MF_SHARES",
    "accountId": "57363",
    "httpEventId": null,
    "tenant_code": "KNAB"
}

What you're doing is declaring a block statement and not a JS or JSON object, that's also probably the reason of the weird formatting.

There are surely ways to fix this. The first thing I can think of is to integrate prettier in monaco, set the language prop to json and let prettier do the heavy lifting of reformatting a js object into a json object. It's quite heavy though

@giacomocerquone
Copy link
Collaborator

any idea here? @marilari88

davc0n added a commit that referenced this issue Sep 7, 2024
@davc0n davc0n closed this as completed in #78 Sep 9, 2024
@davc0n davc0n closed this as completed in 323da59 Sep 9, 2024
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

Successfully merging a pull request may close this issue.

2 participants