Loading ...
Sorry, an error occurred while loading the content.

998browsing and modify a json data structure

Expand Messages
  • hgourvest
    Apr 28, 2008
    • 0 Attachment
      I think browsing and modify a json data structure is a headache for
      most of the json libraries, including mine (delphi json toolkit).
      So I have implemented an expression evaluator directly in the parser.
      This is how I use it:

      obj['path.to[12].an.object'] := value;
      value := obj['path.to[12].an.object'];

      because evaluator is in the parser, I can easy query some datas from
      the json structure and create another one, for example:

      {"prop1": 123, "prop2": ["foo"]} and [prop1, prop2[0]] return [123, "foo"]
      [123, "foo"] and {"prop1": 0, "prop2": [1]} return {"prop1": 123,
      "prop2": ["foo"]}

      or I can set some variables with the same value

      before obj = {};
      obj['[a, b]'] := 1
      after obj = {"a": 1, "b": 1}

      before: [];
      obj['[0, 2]'] := 1
      after: [1, null, 1]

      I have successfully implemented all these features in the delphi json
      toolkit and is only available in the subversion repository:

      Using this new syntax, my code became more readable.

      I have also implemented a "method" datatype for "rpc" and "prototype"
      programming, but it is an other story :)

      I hope it will inspire some of you ..

      PS: english is not my natural language