I was in need for a JSON library, so I made one. I tried to make the parser as fast as possible, using as little string-comparisons and copies as I could.
You can find the code on GitHub. The branch "master" should always be stable. Just copy "fbJson.bi" and the "fbJson"-folder to your project. If you separate the headers, you can also make a library.
The current stable release can be found here:
https://github.com/StringEpsilon/fbJson/releases
You can read and write files, generate new Json objects and arrays from scratch and get values as string.
Example 1: Read object from string:
Code: Select all
#include once "fbJson.bi"
dim as jsonItem item = jsonItem("{""Name"": ""fbJson"", ""Url"": ""https://github.com/StringEpsilon/fbJson"", ""Commits"": 21}")
print item["InvalidKey"].Value ' Access to invalid keys or an index out of bounds just returns an empty item.
print item["Name"].value
print item["Url"].Value
print item[2].Value
' Output:
'
' fbJson
' https://github.com/StringEpsilon/fbJson
' 21
Code: Select all
#include "fbJson.bi"
dim as jsonItem array = jsonItem("[1,2,3,4,5,6,7]")
for i as integer = 0 to array.Count
print array[i].value & " ";
next
' Output:
' 1 2 3 4 5 6 7