[File] Question Regarding is_json.c

Christos Zoulas christos at zoulas.com
Tue Feb 6 15:17:41 UTC 2024


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


More information about the File mailing list