[File] Question Regarding is_json.c

Puvipavan p.puvipavan at gmail.com
Tue Feb 6 15:57:20 UTC 2024


Thanks a lot for the quick response. Looks like I'm using a bit older
version.

$ file test.json
test.json: ASCII text

$ file --version
file-5.38
magic file from /etc/magic:/usr/share/misc/magic

$ cat test.json
[
    {
        "id": "123",
        "labels": []
    }
]

On Tue, Feb 6, 2024 at 8:47 PM Christos Zoulas <christos at zoulas.com> wrote:

> On 2024-02-06 8:39 am, Puvipavan wrote:
> > Hello there,
> >
> > I'm not sure whether this is a right place to ask/recommend any fixes,
> > please direct me to the right place, if I'm wrong.
> >
> > Following JSON is valid according to RFC 7159/8259:
> >
> > [
> >   {
> >     "id": "123",
> >     "labels": []
> >   }
> > ]
> >
> > But it's returning mime type as text/plain whenever there is an empty
> > array.
> >
> > Originally I ran into this issue while using the function finfo_file
> > in PHP. While debugging it, I found out that PHP is internally using
> > your libraries. Looks like following function expecting a value inside
> > an array: https://github.com/file/file/blob/master/src/is_json.c#L180
> >
> > Is it expected or Am I missing something?
>
> Seems to work for me:
>
> [10:15am] 862>./file -m ../magic/magic.mgc empty-array.json
> empty-array.json: JSON text data
> [10:16am] 863>./file --mime -m ../magic/magic.mgc empty-array.json
> empty-array.json: application/json; charset=us-ascii
> [10:16am] 864>./file --version
> file-5.45
> magic file from /usr/local/share/misc/magic
> [10:16am] 865>cat empty-array.json
> [
>    {
>      "id": "123",
>      "labels": []
>    }
> ]
>
> christos
>


-- 
Regards,
*P.Puvipavan*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.astron.com/pipermail/file/attachments/20240206/9eb3942a/attachment-0001.htm>


More information about the File mailing list