Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: JSON Implementation #27

Open
sancarn opened this issue May 30, 2020 · 0 comments
Open

Suggestion: JSON Implementation #27

sancarn opened this issue May 30, 2020 · 0 comments

Comments

@sancarn
Copy link

sancarn commented May 30, 2020

Hello,

I noticed you made a custom implementation of JSON. Just wanted to let you know that there is an implementation of JSON here:

https://github.com/sancarn/VBA-STD-Library/blob/master/src/WIP/stdJSON/JSONBag%20Licensed/JsonBag%202.0/JsonBag.cls
with license:
https://github.com/sancarn/VBA-STD-Library/blob/master/src/WIP/stdJSON/JSONBag%20Licensed/license.txt (Apache2)

Which has several advantages. Mainly it's kept in a single file, but also it's got fairly nice usage syntax:

Example:

json = "{""web-app"":{""servlet"":[{""init-param"":{""templateProcessorClass"":""MyClass""}}]}"

Debug.Print myBag![web-app]![servlet](1)![init-param]![templateProcessorClass] 'Prints MyClass

And construction of JSON is pretty nice also:

With JB
    .Clear
    .IsArray = False 'Actually the default after Clear.

    ![First] = 1
    ![Second] = Null
    With .AddNewArray("Third")
        .Item = "These"
        .Item = "Add"
        .Item = "One"
        .Item = "After"
        .Item = "The"
        .Item = "Next"
        .Item(1) = "*These*" 'Should overwrite 1st Item, without moving it.

        'Add a JSON "object" to this "array" (thus no name supplied):
        With .AddNewObject()
            .Item("A") = True
            !B = False
            !C = 3.14E+16
        End With
    End With
    With .AddNewObject("Fourth")
        .Item("Force Case") = 1 'Use quoted String form to force case of names.
        .Item("force Case") = 2
        .Item("force case") = 3

        'This syntax can be risky with case-sensitive JSON since the text is
        'treated like any other VB identifier, i.e. if such a symbol ("Force"
        'or "Case" here) is already defined in the language (VB) or in your
        'code the casing of that symbol will be enforced by the IDE:

        ![Force Case] = 666 'Should overwrite matching-case named item, which
                            'also moves it to the end.
        'Safer:
        .Item("Force Case") = 666
    End With
    'Can also use implied (default) property:
    JB("Fifth") = Null

    txtSerialized= .JSON
End With

I didn't make the library but it looks pretty damn good in general. Haven't done extensive testing on this though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant