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

Feature request: Support JSON syntax format #1356

Closed
6 tasks
xp44mm opened this issue Apr 9, 2024 · 2 comments
Closed
6 tasks

Feature request: Support JSON syntax format #1356

xp44mm opened this issue Apr 9, 2024 · 2 comments

Comments

@xp44mm
Copy link

xp44mm commented Apr 9, 2024

Use the keyword json to represent each node of a JSON object

let sample = json {
    "s" = json ""
    "d" = json 1.0
    "n" = json null
    "b1" = json true
    "b2" = json false
    "children" = json [ json {} ]
    }

The existing way of approaching:

let sample = Json.Object [
    "s",Json.String ""
    "d",Json.Number 1.0
    "n",Json.Null
    "b1",Json.False
    "b2",Json.True
    "children",Json.Array [ Json.Object [] ]
    ]

Among them, the composite structure object and array will greatly simplify writing.

object

json {} 
json { a = json "hello" }

The existing way of approaching

Json.Object []
Json.Object [ "a",Json.String "hello"]

array

json []
json [ json "hello"; json true; json null ]

The existing way of approaching

Json.Array []
Json.Array [ Json.String "hello";Json.True;Json.Null ]

We can also freely use value binding to composite JSON data:

let a = json 1.0
let b = json [ a ] // json [  json 1.0  ]

let c = 50
let d = json c // json 50

Pros and Cons

The advantages of making this adjustment to F# are ...

The disadvantages of making this adjustment to F# are ...

Extra information

Estimated cost (XS, S, M, L, XL, XXL):

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick these items by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on StackOverflow) and I have searched StackOverflow for discussions of this issue
  • This is a language change and not purely a tooling change (e.g. compiler bug, editor support, warning/error messages, new warning, non-breaking optimisation) belonging to the compiler and tooling repository
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

@vzarytovskii
Copy link

I don't think it's something we're interested in. That's also probably something which can be expressed by generic code, traits, implicit yielding and some conversions.

@vzarytovskii vzarytovskii closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
@ghost
Copy link

ghost commented Apr 9, 2024

For the idea, a custom operator might be able to achieve a similar effect perhaps? x => y :)

json {
   "a" => b
   "c" => d
}

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