1

I would like to have an JSON like data format with the following features:

  • support of arrays (ideal with [item; item; item] as notation and [key: value; key2: value2]), also nested
  • string support, ideal with the following: "foo",0x0a,"bar"
  • hex numbers, bin numbers, decimal numbers

Does anyone know a parser for such a data format written in PHP?

JSON is too inflexible, because keys must be in quotes and associative arrays have a different notation from normal ones and because of the missing string concatenation for special characters.

Asaph
  • 159,146
  • 25
  • 197
  • 199
Florian
  • 3,145
  • 1
  • 27
  • 38

1 Answers1

2

Take a look at YAML. It should come fairly close to what you want. It has lists and associative arrays, knows a number of data types. Support for hexadecimal numbers seems to depend on the parser used.

It doesn't seem to do binary numbers, and can't do string concatenation as outlined in your example, but a well-written parser should be relatively easy to extend accordingly. Also, there is a provision for user-defined data types.

Here is a list of PHP YAML parsers.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Be careful using YAML with php, you will find that many parsers do not conform to the YAML specification fully which may make your data encoding/decoding problematic when exchanging data with a 3rd party. – Keilo Nov 30 '13 at 13:34