83

Recently came across the term JSONC in a YouTube API. I browsed the Web, but found nothing much about it. Can someone explain whether these two are the same or different?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Mandeep Jain
  • 2,304
  • 4
  • 22
  • 38
  • 22
    if you dont know the answer, atleast dont downvote the people who are trying to find it. – Mandeep Jain Feb 14 '13 at 06:58
  • 10
    `jsonc` can also refer to *json with comments* (https://www.npmjs.com/package/jsonc). For example used in [configuration files of VS Code](https://code.visualstudio.com/docs/languages/json#_json-with-comments). – Hotschke Apr 03 '19 at 08:05
  • 1
    jsonc is json with comments in the context of visual code at least! – callback Oct 02 '20 at 17:47

3 Answers3

101

There is also jsonc aka "JSON with comments", created by Microsoft and used by Visual Studio Code. The logic for it can be found here, alas without exhaustive specification (though I'd like to be proven wrong on this).

On top of that there is this project with an actual specification which is also called jsonc, but also does far more than just adding comments.

While there definitely is a use for these technologies, some critical thinking is advised. JSON containing comments is not JSON.

ksclarke
  • 489
  • 5
  • 16
Zyl
  • 2,690
  • 2
  • 22
  • 27
  • 6
    vscode uses this package for jsonc handling - https://github.com/Microsoft/node-jsonc-parser - as included here - https://github.com/Microsoft/vscode/blob/master/extensions/json-language-features/server/package.json – Brian Burns Apr 29 '19 at 00:20
  • 1
    “ JSON containing comments is not JSON”. there are different JSON extensions that support comments, e.g. see https://stackoverflow.com/questions/244777/can-comments-be-used-in-json/7901053#7901053 – Michael Freidgeim Nov 23 '21 at 02:45
  • 1
    I've always had a problem with no comments in JSON. So much I want to explain to future programmers. Meanwhile, JSON where you can cut out some of the unneeded quotes is really appealing; I like the komkom version. the MS version seems unnecessarily complicated, but usable. Tragic that there's so many other things named JSONC. I wish people would google for names before they use them and risk sabotaging their own projects. – OsamaBinLogin Mar 28 '23 at 20:11
23

JSON-C seems to just be a variation of JSON mainly targeted at C development. I.e., from the open source docs, "JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects."ref^1

From the YouTube API perspective (specifically, version 2, not the new version 3), The JSON-C response is just a condensed version of the JSON response (removing "duplicate, irrelevant or easily calculated values").ref^2

Why would the JSON response have "duplicate, irrelevant or easily calculated values" values anyway? Because it is converting the original ATOM XML format directly to JSON in a loseless conversion. You can find out more details here.

However, I would suggest using version 3 of the YouTube Data API. It is much easier to use. =)

codingjeremy
  • 5,215
  • 1
  • 36
  • 39
5

JSONC is an open-source, Javascript API created by Tomás Corral Casas for reducing the size of the amount of JSON data that is transported between clients and servers. It uses two different approaches to achieve this, JSONC.compress and JSONC.pack. More information can be found on the JSONC Github page:

https://github.com/tcorral/JSONC

james.garriss
  • 12,959
  • 7
  • 83
  • 96
  • Is that API the same thing as the mentioned JSON with comments? Or are those completely different and just happened to have the same abbreviation? I suspect, they are different – d.k Jul 16 '21 at 12:39
  • Different. Follow the URLs to see. – james.garriss Jul 16 '21 at 13:11