diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cee1840 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# windsurf rules +.windsurfrules diff --git a/json.db b/json.db index 3650e4c..745b5d8 100755 Binary files a/json.db and b/json.db differ diff --git a/jsonlib.pb b/jsonlib.pb index d63c792..6c5aeba 100755 --- a/jsonlib.pb +++ b/jsonlib.pb @@ -1,4 +1,4 @@ -UseSQLiteDatabase() +UseSQLiteDatabase() Procedure InsertIntoDatabase(key$, parentKey$, type$, value$) query$ = "INSERT INTO json_data (key, parent_key, type, value) VALUES ('" + key$ + "', '" + parentKey$ + "', '" + type$ + "', '" + value$ + "')" @@ -56,13 +56,37 @@ EndProcedure ; Nested array handling Procedure HandleNestedArray(JSONValue, parentKey$) - Dim arrayitems(0) - Debug "Array" + ExtractJSONArray(JSONValue, arrayitems()) - - For i = 0 To ArraySize(arrayitems()) - Debug "Array item" + arrayitems(i) - InsertIntoDatabase(key$,parentKey$,"array",Str(arrayitems(i))) - Next i + arraySize = JSONArraySize(JSONValue) + + For arrayIndex = 0 To arraySize - 1 + elementValue = GetJSONElement(JSONValue, arrayIndex) + arrayItemKey$ = parentKey$ + "[" + Str(arrayIndex) + "]" + + Select JSONType(elementValue) + Case #PB_JSON_String + value$ = GetJSONString(elementValue) + InsertIntoDatabase(arrayItemKey$, parentKey$, "String", value$) + + Case #PB_JSON_Number + value$ = StrD(GetJSONDouble(elementValue)) + InsertIntoDatabase(arrayItemKey$, parentKey$, "Number", value$) + + Case #PB_JSON_Boolean + value$ = Str(GetJSONBoolean(elementValue)) + InsertIntoDatabase(arrayItemKey$, parentKey$, "Boolean", value$) + + Case #PB_JSON_Object + InsertIntoDatabase(arrayItemKey$, parentKey$, "Object", "(nested object)") + HandleNestedObject(elementValue, arrayItemKey$) + + Case #PB_JSON_Array + InsertIntoDatabase(arrayItemKey$, parentKey$, "Array", "(nested array)") + HandleNestedArray(elementValue, arrayItemKey$) + + Default + InsertIntoDatabase(arrayItemKey$, parentKey$, "Unknown", "(unknown type)") + EndSelect + Next EndProcedure ; worry about the database init later @@ -127,8 +151,8 @@ EndIf CloseDatabase(0) ; IDE Options = PureBasic 6.12 LTS (Linux - x64) -; CursorPosition = 63 -; FirstLine = 43 +; CursorPosition = 126 +; FirstLine = 89 ; Folding = - ; EnableXP ; DPIAware \ No newline at end of file