[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] / [Samples] / JSON
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Thu Apr 26 14:54:55 PDT 2012

Contents


    JSON -- JavaScript Object Notation

      Purpose

      A light weight and language independent notation for exchanging data between different programs. It is based on the Javascript notations.

      Compare YAML [ languages.html#YAML ] and XML [ languages.html#XML ] which have similar purposes but different philosophies.

      See Also

    1. JSON::= See http://www.json.org/. [ JSON ] (wikipedia entry).

      Syntax of JSON

        Based on JSON above.

        Standard Syntactic Shorthand

      1. #X::= "" | X #X.
      2. O(X)::= ""|X, optional.
      3. L(x)::= X | X "," L(X), lists.
      4. N(X)::= X #X.

        Lexical rules

        Extra whitespace between lexemes are ignored.

        Objects

      5. object::= "{" "}" | "{" L(member) "}".
      6. member::= string ":" value.
         	{"species":"Snake", "id":1234, "length":5.5, "male":true}

        Arrays

      7. array::="[" L(value) "]".
         	[1,4,9,16]
         	[true,false,true,false]
        JSON arrays can be heterogenous
         	[1,true,"foo"]
        with thanks to Laurent(5:30pm California time Apr 17 2012).

        Values

      8. value::= string | number | object | array | true | false| null.

      9. true::lexeme.
      10. false::lexeme.
      11. null::lexeme.

      12. string::=quotes quotes | quotes N(char) quotes.
      13. quotes::lexeme= "\"".

      14. char::=any Unicode character except quotes or backslash or control character | escaped_character | unicoded_character.
      15. backslash::lexeme= "\\".

      16. escaped_character::= backslash ( quotes | backslash | slash | "b" | "f" | "n"| "r" | "t").
        Table
        Escaped CharacterMeaning
        \""
        \\\
        \//
        \bBackspace
        \fFormfeed
        \nNewline
        \rReturn
        \tHorizontal tab

        (Close Table)

      17. unicode_character::= hex_digit ^ 4, four hex digits.

      18. hex_digit::= "0..9" | ignore_case("A".."F"), (Stephen Parker checked this out on April 17th 2012.

      19. number::= int | int frac | int exp | int frac exp.

      20. int::=O("-") ( digit | digit1_9 digits ).

      21. digits::= N(digit), 1 or more digits.
      22. digit::="0".."9".
      23. digit1_9::="1".."9".

      24. frac::= dot digits.
      25. exp::=e digits.

      26. dot::lexeme= ".".
      27. e::= ("e"|"E")O("+"|"-").

      . . . . . . . . . ( end of section Syntax of JSON) <<Contents | End>>

      Static Semantics of JSON -- UML -- Abstract Syntax

      [UML diagram of concepts in JSON]

      Note: above needs some work!

      Semantics of JSON

        JSON describes data/objects by a human readable interpretation of the different Values:
      1. JSON_Value::= String | Numbers | @ | {{}} | String <>-> JSON_Value | Nat0<>->JSON_Value.

        The semantic sets map nicely into MATHS sets.

      2. String::=#Unicode. [ maths/types.html#Unicode ]

      3. Numbers::=Integer | Real.
      4. Integer::= See http://csci.csusb.edu/dick/maths/logic_6_Numbers..Strings.html#Integer.
      5. Real::= See http://csci.csusb.edu/dick/maths/math_42_Numbers.html#Real Numbers.

        We use a partial maps ( dom <>-> cod) to represent the meaning of JSON objects and arrays. Nat0 is the standard symbol for the set of natural numbers including 0.

      6. Nat0::= See http://csci.csusb.edu/dick/maths/math_42_Numbers.html#Nat0.

        Next we describe the meaning map from the syntax to the semantics. The traditional symbol for this mapping is μ.

      7. μ::=meaning.
      8. meaning:: Value -> JSON_Value.

        I define it "piecewise" on each type of value in turn --

      9. μ(true)::= STANDARD.true.
      10. μ(false)::= STANDARD.false.
      11. μ(null)::={}, possibly.
      12. μ("")::="".
      13. For m: Member, μ(m)::= (m.string +> m.value).
      14. For x:Object, μ(x)::= |[m:x.member]μ(x).
      15. For z:Array, TBD.

      . . . . . . . . . ( end of section Semantics of JSON) <<Contents | End>>

    . . . . . . . . . ( end of section JSON -- JavaScript Object Notation) <<Contents | End>>

End