juan_gandhi: (VP)
So, if this is the data format exclusively for machines, why not use ASN.1 instead? Pretty compact. Or protobuffers, and the like.

No, the advantage of JSON is that a) it's readable; b) it's executable (but everybody's afraid to execute it).

Parsing JSON the way data are written as literals in JavaScript is not harder than interpreting JavaScript. Which is fast. So we could add comments, quoteless names, hanging commas, multiline string literals. It's not a big deal.

The disadvantage is that a bunch of dumb software would not understand it. But the software is already dumb. I remember pinging Crockford when I found his implementation of JSON has some kind of error, forgot what.

It's not a big deal to start understanding more.

What JSON is definitely not good for is storing data and searching data by the key. Any hierarchical structure is not good. To store, data should be flattened.

Now properties.

People use JSON (good, readable), YAML (good, readable), XML (stupid, unreadable, traditional), HOCON (better than YAML, readable).

Of course configs, written by humans, should better be in HOCON.
But JSON is definitely read by humans; and pretty often written by humans, too. So why not give more freedom to the people? Gradually, of course.

json5

Aug. 20th, 2014 01:25 pm
juan_gandhi: (VP)
http://json5.org/

{
    foo: 'bar',
    while: true,

    this: 'is a \
multi-line string',

    // this is an inline comment
    here: 'is another', // inline comment

    /* this is a block comment
       that continues on another line */

    hex: 0xDEADbeef,
    half: .5,
    delta: +10,
    to: Infinity,   // and beyond!

    finally: 'a trailing comma',
    oh: [
        "we shouldn't forget",
        'arrays can have',
        'trailing commas too',
    ],
}
juan_gandhi: (VP)
It's recursive. An array inside a map inside a map, etc. You need a context-free grammar to parse it.
But this can be fixed. See how.

1. You can convert array into a map, right? s"[[$i]]" -> arrayValue(i)

So, generally speaking, can have just maps.

2. If we ban (or escape) dots ('.') inside keys, we can "flatten" the map of maps of maps, just by merging keys.

{"a" -> {
  "key1" -> {
    "[[0]]" -> "value at a.key1[0]"
...
    }
  }
}


will be
{"a.key1.[[0]]" -> "value at a.key1[0]"
 ...
}


3. We ban or escape quotes in keys, and html-escape quotes in values, s/"\""/"""/g, we can get rid of quotes in keys and have only delimiting quotes in values.

What does it give us? We get Regular Language. That easy.

What's the point of having a regular language? Tons of them.

- You can keep it in SQL and match using regular SQL statements.
- You can check or extract data in shell scripts.
- You can parse it efficiently in your code, no need for parsers/combinators.

P.S. And fuck Crockford, he's an ignorant asshole anyway.
juan_gandhi: (VP)
here the author hints we can have define fixed point of Succ. Well, it's Nat.

here Dan Piponi discusses in terms too obscure to me (yet) the aspects that kind of evade my comprehension.

here data and codata are defined simply as initial algebras and terminal coalgebras (over a comonad?)

It all looks logical but weird.

My practical gut feeling is that there's a BIG difference between potentially infinite data structures and strictly finite ones.

E.g. If I have a fully (c-like) structure, with no lists etc inside, I can successfully match it "in real time"; but if I have something that has a lazy list or whatever inside, it's impossible, and we actually have to work with it in a totally different way. Scan it, not match. With an exception of a map or a function, which we can ask for a value for a given key, without bothering with whatever else it contains.

There must be some pretty simple philosophy there, but somehow I cannot grasp it yet.

Update: Observational Type Theory may be the answer.

"Potentially more important than the formalisation of mathematical theories is the development of correct software for communicatin systems, which typically exhibit infinite behaviour and hence demand observational reasoning."

Practically, it may also tell us why we do not need DTD or type-safe JSON/REST.
juan_gandhi: (Default)
Spent like an hour trying to figure out how to serialize to json the object I build from json (to pass around the network); then it occurred to me it's immutable. Why not keep the source, eh. Like class files, they'd be happier if they just had the source code accompanying them naturally somewhere, eh.

So there. I just store the object's own source. Neat, eh.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
171819 20212223
2425 2627282930
31      

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 27th, 2025 09:54 pm
Powered by Dreamwidth Studios