Skip to main content
added 171 characters in body
Source Link
doppelgreener
  • 7.3k
  • 7
  • 43
  • 69

Use##Use JSON.##

(Building on Munificent's response, and largely in response to your concerns expressed elsewhere)

You've mentioned in another comment it stillconcern that JSON has the issue of wasting space naming elements, like XML. It doesn't.

JSON is built on two structures: name/value pairs (objects) and ordered lists of values (arrays).

You are complaining about objects whilst forgetting arrays exist XML is built only on name/value pairs.

Using mainly objectsIf you could dothink JSON relies on objects you've been reading JSON that's built to be self-descriptive and human-readable, like this (using octal digit pairs to represent single bytes):

{
    "some": ...,
    "data": ...,
    "fields": ...,
    "cars": [
        {"name":"nissan""greg","num1""cost":8C,"num2""speed":FA,"num3""age":2A04,"num4""driverID":384FFFFF},
        {"name":"holden""ole rustbucket","num1""cost":00,"num2""speed":00,"num3""age":042A,"num4""driverID":04FF54A9}
    ]
}

(You could end up with a byte with the value 2C, which a parser could mistake for a comma, but this isn't an issue if However you know the length of each field and so understand that the 2C is part of a value and not the markup)

Youalso have the option of dropping objects completely, howeverwriting it like this, asso long as you know where everything will be, and that the 4th (and so can look for index 4, rather than object "cars", to get your list of the main array is cars, etc):

{
    [
        ...,
        ..., 
        ...,
        [["nissan"[["greg",8C,FA,2A04,384FFFFF],["holden"["ole rustbucket",00,00,042A,04FF54A9]],
        ...,
    ]
}

Does it get more concise than just having [, ], , and your values?

Well, it does if you're willing to just save the whole thing asget closer and closer to a pure binary stream and forget about data formats altogether.

"cars":{"names":["greg","ole rustbucket"],"stream":8CFA04384FFFFF00002A04FF54A9}
or
[["greg","ole rustbucket"],8CFA04384FFFFF00002A04FF54A9]

Just don't shoot yourself in the leg by optimising too much.

Use JSON.

You've mentioned in another comment it still has the issue of wasting space naming elements. It doesn't.

JSON is built on two structures: name/value pairs (objects) and ordered lists of values (arrays).

You are complaining about objects whilst forgetting arrays exist.

Using mainly objects you could do this (using octal digit pairs to represent single bytes):

{
    "some": ...,
    "data": ...,
    "fields": ...,
    "cars": [
        {"name":"nissan","num1":8C,"num2":FA,"num3":2A,"num4":384FFFFF},
        {"name":"holden","num1":00,"num2":00,"num3":04,"num4":04FF54A9}
    ]
}

(You could end up with a byte with the value 2C, which a parser could mistake for a comma, but this isn't an issue if you know the length of each field and so understand that the 2C is part of a value and not the markup)

You have the option of dropping objects completely, however, as long as you know where everything will be, and that the 4th index of the main array is cars, etc:

{
    [
        ...,
        ..., 
        ...,
        [["nissan",8C,FA,2A,384FFFFF],["holden",00,00,04,04FF54A9]],
        ...,
    ]
}

Does it get more concise than just having [, ], , and your values?

Well, it does if you're willing to just save the whole thing as a binary stream and forget about data formats altogether.

##Use JSON.##

(Building on Munificent's response, and largely in response to your concerns expressed elsewhere)

You've mentioned concern that JSON has the issue of wasting space naming elements, like XML. It doesn't.

JSON is built on two structures: name/value pairs (objects) and ordered lists of values (arrays). XML is built only on name/value pairs.

If you think JSON relies on objects you've been reading JSON that's built to be self-descriptive and human-readable, like this (using octal digit pairs to represent single bytes):

{
    "some": ...,
    "data": ...,
    "fields": ...,
    "cars": [
        {"name":"greg","cost":8C,"speed":FA,"age":04,"driverID":384FFFFF},
        {"name":"ole rustbucket","cost":00,"speed":00,"age":2A,"driverID":04FF54A9}
    ]
}

However you also have the option of writing it like this, so long as you know where everything will be (and so can look for index 4, rather than object "cars", to get your list of cars):

{
    [
        ...,
        ..., 
        ...,
        [["greg",8C,FA,04,384FFFFF],["ole rustbucket",00,00,2A,04FF54A9]],
        ...,
    ]
}

Does it get more concise than just having [, ], , and your values?

Well, it does if you're willing to just get closer and closer to a pure binary stream.

"cars":{"names":["greg","ole rustbucket"],"stream":8CFA04384FFFFF00002A04FF54A9}
or
[["greg","ole rustbucket"],8CFA04384FFFFF00002A04FF54A9]

Just don't shoot yourself in the leg by optimising too much.

added 226 characters in body; added 42 characters in body; added 4 characters in body
Source Link
doppelgreener
  • 7.3k
  • 7
  • 43
  • 69

Use JSON.

You've mentioned in another comment it still has the issue of wasting space naming elements. It doesn't.

JSON is built on two structures: name/value pairs (objects) and ordered lists of values (arrays).

You are complaining about objects whilst forgetting arrays exist.

Using mainly objects you could do this (using octal digit pairs to represent single bytes):

{
    "some": ...,
    "data": ...,
    "fields": ...,
    "cars": [
        {"name"name":"ford""nissan","num1":8C,"num2":FA,"num3"num3":"2A2A,"num4":384FFFFF},
        {"name"name":"holden","num1":00,"num2":00,"num3"num3":"0404,"num4":04FF54A9}
    ]
}

(That's using octal digits to represent bytes. In other wordsYou could end up with a byte with the value 2C, each pair of digitswhich a parser could mistake for a comma, but this isn't an issue if you see thereknow the length of each field and so understand that the 2C is my representationpart of a single byte in your file.value and not the markup)

But you alsoYou have the option of dropping objects completely, however, as long as you know where everything will be, and that the 4th index of the main array is cars, etc:

{
    [
        ...,
        ..., 
        ...,
    [["ford"    [["nissan",8C,FA,2A,384FFFFF],["holden",00,00,04,04FF54A9]],
        ...,
    ] 
}

Does it get more concise than just having [, ], , and your values?

Well, it does if you're willing to just save the whole thing as a binary stream and forget about data formats altogether.

Use JSON.

You've mentioned in another comment it still has the issue of wasting space naming elements. It doesn't.

JSON is built on two structures: name/value pairs (objects) and ordered lists of values (arrays).

You are complaining about objects whilst forgetting arrays exist.

Using mainly objects you could do this:

{
    "some": ...,
    "data": ...,
    "fields": ...,
    "cars": [
        {"name:"ford","num1":8C,"num2":FA,"num3:"2A,"num4":384FFFFF},
        {"name:"holden","num1":00,"num2":00,"num3:"04,"num4":04FF54A9}
    ]
}

(That's using octal digits to represent bytes. In other words, each pair of digits you see there is my representation of a single byte in your file.)

But you also have the option of dropping objects completely:

{[
    ...,
    ..., 
    ...,
    [["ford",8C,FA,2A,384FFFFF],["holden",00,00,04,04FF54A9]],
    ...,
]}

Does it get more concise than just having [, ], , and your values?

Well, it does if you're willing to just save the whole thing as a binary stream and forget about data formats altogether.

Use JSON.

You've mentioned in another comment it still has the issue of wasting space naming elements. It doesn't.

JSON is built on two structures: name/value pairs (objects) and ordered lists of values (arrays).

You are complaining about objects whilst forgetting arrays exist.

Using mainly objects you could do this (using octal digit pairs to represent single bytes):

{
    "some": ...,
    "data": ...,
    "fields": ...,
    "cars": [
        {"name":"nissan","num1":8C,"num2":FA,"num3":2A,"num4":384FFFFF},
        {"name":"holden","num1":00,"num2":00,"num3":04,"num4":04FF54A9}
    ]
}

(You could end up with a byte with the value 2C, which a parser could mistake for a comma, but this isn't an issue if you know the length of each field and so understand that the 2C is part of a value and not the markup)

You have the option of dropping objects completely, however, as long as you know where everything will be, and that the 4th index of the main array is cars, etc:

{
    [
        ...,
        ..., 
        ...,
        [["nissan",8C,FA,2A,384FFFFF],["holden",00,00,04,04FF54A9]],
        ...,
    ] 
}

Does it get more concise than just having [, ], , and your values?

Well, it does if you're willing to just save the whole thing as a binary stream and forget about data formats altogether.

Source Link
doppelgreener
  • 7.3k
  • 7
  • 43
  • 69

Use JSON.

You've mentioned in another comment it still has the issue of wasting space naming elements. It doesn't.

JSON is built on two structures: name/value pairs (objects) and ordered lists of values (arrays).

You are complaining about objects whilst forgetting arrays exist.

Using mainly objects you could do this:

{
    "some": ...,
    "data": ...,
    "fields": ...,
    "cars": [
        {"name:"ford","num1":8C,"num2":FA,"num3:"2A,"num4":384FFFFF},
        {"name:"holden","num1":00,"num2":00,"num3:"04,"num4":04FF54A9}
    ]
}

(That's using octal digits to represent bytes. In other words, each pair of digits you see there is my representation of a single byte in your file.)

But you also have the option of dropping objects completely:

{[
    ...,
    ..., 
    ...,
    [["ford",8C,FA,2A,384FFFFF],["holden",00,00,04,04FF54A9]],
    ...,
]}

Does it get more concise than just having [, ], , and your values?

Well, it does if you're willing to just save the whole thing as a binary stream and forget about data formats altogether.