Author Topic: Tiny-Json (read-only Json parser)  (Read 270 times)

airr

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Tiny-Json (read-only Json parser)
« on: May 01, 2024, 08:52:55 PM »
"Another One" - DJ Khallid

Here's a demo of a read-only Json lib (static 64-bit lib built with PellesC)

Lib, header, and test json file attached.

Git repo: https://github.com/rafagafe/tiny-json

Code: [Select]
'**************************************************************
' Tiny-Json demo by AIR - 2024-05-01
' Github repo for Tiny-Json: https://github.com/rafagafe/tiny-json
'**************************************************************

#include "tinyjson.h"

$pragma comment(lib, "tinyjson.lib")

Macro SIZE(x) = (Sizeof(x) / Sizeof(*x))

Dim a$
Dim As json_t mem[BCXSTRSIZE]
Dim As Const json_t* json, phoneList, phone

a$ = Loadfile$("test.json")
json = json_create( a$, mem, SIZE(mem) )

If Not json Then
    Print "json_create failed"
    End = 1
End If

Print "FirstName: ", json_getPropertyValue$( json, "firstName" )
Print "LastName: ", json_getPropertyValue$( json, "lastName" )
Print "Age: ", json_getPropertyValue$( json, "age" )

phoneList = json_getProperty( json, "phoneList" )

Print "Phone List:"

phone = json_getChild( phoneList )

While phone
    Print Space$(4), "Type: ", json_getPropertyValue$( phone, "type" ), ", Number: ", json_getPropertyValue$( phone, "number" )
    phone = json_getSibling( phone )
Wend


AIR.