New Releases: SRP Utilities 2.2 and SRP Editor 3.3.3

SRP Utilities gets a new Json API that we think you’re really going to like while the SRP Editor gets a little love.

The Status Quo

SRP Json has gotten a lot of use over the years, but there’s one lingering issue with it.

Handles. Oh, the handles.

Json is hierarchical and designed around object orientation. BASIC+ typically deals with objects by returning handles to them. It’s how RevDotNet works. It’s even how the OI Presentation Server works, only we use names instead of handles. When SRP Json was developed, handles were the obvious design choice.

But it’s so cumbersome. Let’s create the following Json text:

{
    "employees": [
        {
            "firstname": "John",
            "lastname": "Doe",
            "age": 21
        },
        {
            "firstname": "Anna",
            "lastname": "Smith",
            "age": 32
        },
        {
            "firstname": "Peter",
            "lastname": "Jones",
            "age": 43
        }
    ],
    "count": 4,
    "active": true,
    "alwaysnull": null,
    "decimal": 4.321,
    "alwaysstring": "4.321"
}

Here is the SRP Json code to do it:

RootHandle = 0
If SRP_Json(RootHandle, "New") then
    EmployeeArrayHandle = 0
    If SRP_Json(EmployeeArrayHandle, "New", "Array") then
        If SRP_Json(SingleEmployeeHandle, "New") then
            SRP_Json(SingleEmployeeHandle, "SetValue", "firstName", "John")
            SRP_Json(SingleEmployeeHandle, "SetValue", "lastName", "Doe")
            SRP_Json(SingleEmployeeHandle, "SetValue", "age", "21")
            SRP_Json(EmployeeArrayHandle, "Add", SingleEmployeeHandle)
            SRP_Json(SingleEmployeeHandle, "Release")
        end
        If SRP_Json(SingleEmployeeHandle, "New") then
            SRP_Json(SingleEmployeeHandle, "SetValue", "firstName", "Anna")
            SRP_Json(SingleEmployeeHandle, "SetValue", "lastName", "Smith")
            SRP_Json(SingleEmployeeHandle, "SetValue", "age", "32")
            SRP_Json(EmployeeArrayHandle, "Add", SingleEmployeeHandle)
            SRP_Json(SingleEmployeeHandle, "Release")
        end
        If SRP_Json(SingleEmployeeHandle, "New") then
            SRP_Json(SingleEmployeeHandle, "SetValue", "firstName", "Peter")
            SRP_Json(SingleEmployeeHandle, "SetValue", "lastName", "Jones")
            SRP_Json(SingleEmployeeHandle, "SetValue", "age", "43")
            SRP_Json(EmployeeArrayHandle, "Add", SingleEmployeeHandle)
            SRP_Json(SingleEmployeeHandle, "Release")
        end
        SRP_Json(RootHandle, "Set", "employees", EmployeeArrayHandle)
        SRP_Json(EmployeeArrayHandle, "Release")		
    end
    SRP_Json(RootHandle, "SetValue", "count", 4)
    SRP_Json(RootHandle, "SetValue", "active", 1, "Boolean")
    SRP_Json(RootHandle, "SetValue", "alwaysnull", "", "Null")
    SRP_Json(RootHandle, "SetValue", "decimal", 4.321)
    SRP_Json(RootHandle, "SetValue", "alwaysstring", 4.321, "String")
    Json = SRP_Json(RootHandle, "Stringify", "STYLED")
    SRP_Json(RootHandle, "Release")	
end

Handle after handle, too much typing, and for the love of IBM, don’t forget to RELEASE YOUR HANDLES!!!

SRP JsonX

SRP Utilities 2.2 introduces a new Json API we like to call SRP Json Express, or JsonX for short. Kiss handles goodbye and never worry about forgetting to release. Here’s how to create the same Json using SRP JsonX:

SRP_JsonX_Begin('MyDocument', '{')
    SRP_JsonX('employees', '[')
        SRP_JsonX('{')
            SRP_JsonX('firstname', 'John')
            SRP_JsonX('lastname', 'Doe')
            SRP_JsonX('age', 21)
        SRP_JsonX('}')
        SRP_JsonX('{')
            SRP_JsonX('firstname', 'Anna')
            SRP_JsonX('lastname', 'Smith')
            SRP_JsonX('age', 32)
        SRP_JsonX('}')
        SRP_JsonX('{"firstname":"Peter", "lastname":"Jones", "age":43}')
    SRP_JsonX(']')
    SRP_JsonX('count', 4)
    SRP_JsonX('active', 1, 'Bool')
    SRP_JsonX('alwaysnull')
    SRP_JsonX('alwaysstring', 4.321, 'String')
Json = SRP_JsonX_End('Pretty')

I know, right?

SRP Json needed handles because it was stateless. It didn’t know where you were going or what you intended to do next. SRP JsonX, meanwhile, maintains a current document and current location within that document. The end result is an API that pretty much just looks like you’re writing Json.

Neat, huh?

Fast, Easy Parsing

SRP JsonX uses the C++ RapidJson API under the hood with a few customizations to make it work nicely with BASIC+. The parser is fast. I mean, really fast! In our tests, it can fully parse a 40mb file into memory in about 170ms.

Once a document is parsed, you pull out values using the same path syntax as SRP Json.

SRP_JsonX_Parse('MyParsedDoc', Json)
    FirstName = SRP_JsonX_Get('employees[2].firstname')
    LastName  = SRP_JsonX_Get('employees[2].lastname')
SRP_JsonX_End()

This, of course, is just a taste. See the documentation for more details.

SRP Editor 3.3.3

Oh, yeah, we also released a little update for the SRP Editor. In the SRP JsonX example above, we indented some lines to make it look more Json-like, but if we click the Format button in the SRP Editor, those indents disappear faster than IT support in the midst of a production system GFE.

As of version 3.3.3, you can surround any code whose formatting you want to preserve within #pre and #endpre directives.

#pre
SRP_JsonX_Begin('MyDocument', '{')
    SRP_JsonX('employees', '[')
        SRP_JsonX('{')
            SRP_JsonX('firstname', 'John')
            SRP_JsonX('lastname', 'Doe')
            SRP_JsonX('age', 21)
        SRP_JsonX('}')
    SRP_JsonX(']')
Json = SRP_JsonX_End('Pretty')
#endpre

Now, when you click the Format button, your oh-so-pretty JsonX code is left unaccosted.

OI doesn’t know the #pre and #endpre directives, so it will throw compiler errors if you don’t use the SRP_PreCompiler from SRP Utilities 2.2 which is automatically installed when you use the SRP Editor installer. If you use #pre in your code, the SRP Editor will insert the precompiler directive for you. Besides, it’s probably already there. We know how much you love the For Each loop.

Available Now

SRP Utilities 2.2 and SRP Editor 3.3.3 are available now for download. SRP JsonX is yours, free of charge, so have a blast with it. The original SRP Json isn’t going anywhere, so you don’t have to worry about any breaking changes there. You can port your code at your convenience.

Go have some Json fun.

4 Responses to New Releases: SRP Utilities 2.2 and SRP Editor 3.3.3

  • Bill Coale says:

    Well now Kevin, THAT is some funny writing:
    “but if we click the Format button in the SRP Editor,
    those indents disappear faster than IT support in the
    midst of a production system GFE.”
    I’m still smiling every time I re-read that.

    • Don Bakke says:

      No guarantees. Officially we only support those versions of OpenInsight that Revelation supports. That said, the 32bit version of our products will always support OI 9.4. Revelation made changes between OI 8.x and OI 9.x related to OLE support so we cannot ensure there won’t be any problems with pre-OI 9.x systems.

Leave a Reply