Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maximum length of a field name in JSON

Tags:

json

What is the maximum length of a field name in JSON?

For example, in the following json document

{
    "myfield":"value"
}

can I make "myfield" as long as 100 characters?

like image 821
sarfarazsajjad Avatar asked Oct 23 '25 19:10

sarfarazsajjad


1 Answers

JSON is a format like XML and it doesn't have any limits. However, the JSON parser may impose a limit on the size of the document as a whole:

  • in ASP.Net, there's "MaxJsonLength". The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data.

  • in PHP, there's no max length for a JSON string. PHP will fail parsing a JSON string if it reaches the PHP memory_limit or if the JSON string posted is larger than the PHP post_max_size.

  • etc.

A hundred characters won't cause a problem. If you reach 4MB of data, you should probably look into reducing the size of the JSON document or finding a workaround.

EDIT

To clarify my point, there's no limit for a name or value inside a JSON document. If there's any limit, it is applied to the size of the JSON document as a whole.

like image 161
Wissam El-Kik Avatar answered Oct 26 '25 08:10

Wissam El-Kik