Results 1 to 7 of 7

Thread: cJsonPath class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    1,449

    Default cJsonPath class

    OK, as I mentioned in the JsonConfig.pkg thread here, I found a need to use the same approach to getting either objects or values from deep inside pretty complex JSON.

    I was finding that a real PitA to do, with my code getting very deeply nested. It is in a web app, so you tend to start fairly deep, but when you have lines starting on column 65... well, that isn't good! Also, it is a whole lot of code I really didn't want cluttering up my logic, so...

    I created my cJsonPath class.

    It provides two public methods:

    Function JsonAtPath, which returns the JSON object handle at the specified path.
    Function ValueAtPath, which returns the value in the JSON object at the specified path.

    If you use it right, I think it works OK; if you use it wrong, who knows? Life is too short to try to test all the myriad ways things can be done wrong!

    Usage might be:
    Code:
        Move (JsonAtPath(oJPath, hoJson, "foo.bar.baz[5][3].Mork[0][4][3]")) to hoObj
    OR
        Get ValueAtPath of oJPath hJoson "foo.bar.baz[5][3].Mork[0][4][3]" to sVal
    Here is the class package: cJsonPath.pkg

    I have tested it somewhat, but obviously you use it at your own risk. YMMV!

    Please report bugs - most especially memory leaks (which were the very devil to eliminate!) - to mpeat at unicorninterglobal dot com.

    Mike
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •