News for hackers. Stuff that matters.
Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by AdieuToLogic on Monday January 30, 2023 @09:13PM (#34590004)
Just for fun, I wondered if YAML '#' comments could exist within a multi-line formatted JSON file.

I cannot say the below holds for all YAML libraries, but can say the below works.

Assume there is a file named "foo.yaml" which has the following content:

  {
    # this is a comment
    "hello" : "world",
    array : [
      # first number
      1,
  
      # second number
      2
      ]
  }
Running:

  ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' < foo.yaml
Yields the below without error:

  {
    "hello": "world",
    "array": [
      1,
      2
    ]
  }
HTH
Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by verdverm on Tuesday January 31, 2023 @07:42AM (#34594367)
you can reduce further this by running:

    cue export foo.yaml --out json
If you have an existing JSON file, add // comments wherever and run:

    cue export cue: - --out json < file.json
The `cue: -` tells cue how to interpret stdin and has many options