views:

33

answers:

1

Hi, 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 to 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.

+2  A: 

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.

Pekka
thank you, especially for your update :)
levu