MediaArea / MediaInfo

Convenient unified display of the most relevant technical and tag data for video and audio files.
https://MediaArea.net/MediaInfo
BSD 2-Clause "Simplified" License
1.41k stars 160 forks source link

Numbers are always strings in JSON output #442

Open paxter opened 4 years ago

paxter commented 4 years ago

As the title states. All JSON fields are always strings. But numbers should be numbers and no strings.

For example

{
"media": {
"@ref": "media.mkv",
"track": [
{
"@type": "General",
"UniqueID": "546432143543654365143543543545863685869",
"VideoCount": "1",
"AudioCount": "1",
"FileExtension": "mkv",
"Format": "Matroska",
"Format_Version": "4",
"FileSize": "696584825",
"Duration": "2742.240",
"OverallBitRate": "2032163",
"FrameRate": "25.000",
[...]

should be

{
"media": {
"@ref": "media.mkv",
"track": [
{
"@type": "General",
"UniqueID": "546432143543654365143543543545863685869",
"VideoCount": 1,
"AudioCount": 1,
"FileExtension": "mkv",
"Format": "Matroska",
"Format_Version": 4,
"FileSize": 696584825,
"Duration": "2742.240",
"OverallBitRate": 2032163,
"FrameRate": "25.000",
[...]

I'm unsure about cases, where you need some more numbers on floating point numbers after the point. Maybe a string is the best solution there (Duration, FrameRate, UniqueID etc.).

JeromeMartinez commented 4 years ago

But numbers should be numbers and no strings.

It was a quick and dirty way to create a JSON output. doing a difference between numbers vs string is more work (e.g. is a number of 256 bit accepted? It is the size of a number with some Unique IDs...)

But actually we got last month a sponsor who wants this too, so should not be long to implement.

paxter commented 4 years ago

Thanks for your reply.

As far as I know, JSON accepts every valid number (if your underlaying platform supports it). You can check the RFC: https://tools.ietf.org/html/rfc7159#page-6

In my case (MacOS;PHP) the number of UniqueID is to long and will be translated from 546432143543654365143543543545863685869 to 5.4643214354365E+38.

And floating point numbers could be a problem too. For example the framerate will be translated from 25.000 to 25 on my system. So indeed, it's not that simple.

paxter commented 4 years ago

I also noticed, that XML/JSON (and others, I think) output uses language specific keys for some cases. For example:

German:

[...]
"@type": "Allgemein",
"UniqueID": "546432143543654365143543543545863685869",
[...]

English:

[...]
"@type": "General",
"UniqueID": "546432143543654365143543543545863685869",
[...]

I think, it's not a good idea to use different keys for different languages. It's harder to process the outputs automatically.

JeromeMartinez commented 4 years ago

I think, it's not a good idea to use different keys for different languages. It's harder to process the outputs automatically.

It was not intended, most users of XML or JSON use the command line so English only, we didn't catch it sooner. We faced this issue when we localized the Android app (we use the XML output as an intermediate storage), we fixed it now but only in dev snapshots for other platforms.