cJSON parser: Clarion port

cJSON is ultralightweight JSON parser in ANSI C. This repository contains cJSON port to Clarion:

The documentation can be found here

5 Likes

v1.09 is available, now different encodings (code pages) are supported.

There have been many updates over the past 4 years. Actual version is 1.24.

2 Likes

There have been many updates over the past 2 years. Actual version is 1.50.
Also there is an utility for creating a Clarion data structure corresponding to the json structure:

Merry Christmas!

5 Likes

Hello Mike,

I want to sincerely thank you for the valuable contribution you have made. I really appreciate it and certainly recognize the great effort that has gone into its development.

Once again, thank you very much for your dedication and support.

Merry Christmas and New Year

1 Like

Thank you Mike for your great tools and excellent support!

Merry Christmas!

Best regards
Jeffrey

I agree with Carlos and Jeffrey about your excellent work with this version of cJson and now with the cJson Mapper.
Excellent work that makes Clarion a very suitable environment for any modern development.

Merry Christmas
Gustavo.

I agree and thank you too for your great work, Mike!!

Congratulations Mike and thank you very much!!

Hello everyone!!

Here I am, always struggling with JSON, haha!

I’m working with “cJSON mapper” and I have a question about the JSON I’m trying to read.

“respuesta”, “comprobantesFiscales”, “comprobantes”, “otrosComprobantes” are arrays.

Should they be QUEUED in the “MyObject” structure?

Thanks


  INCLUDE('cjson.inc'), ONCE
  MAP
    INCLUDE('printf.inc'), ONCE
  END

sJson                        STRING(''  |
    & '{{'  |
    & '  "estado":  "ok",'  |
    & '  "respuesta":  [{{'  |
    & '      "puntoventa":  1,'  |
    & '      "emision":  "CAE",'  |
    & '      "comprobantesFiscales":  [{{'  |
    & '          "codigoTipoComprobante":  6,'  |
    & '          "comprobantes":  [{{'  |
    & '              "monto":  5200,'  |
    & '              "numeroNodo":  1,'  |
    & '              "numeroTransaccion":  6,'  |
    & '              "numeroComprobante":  133,'  |
    & '              "horaEmision":  "112404"'  |
    & '            }]'  |
    & '        }]'  |
    & '    },  {{'  |
    & '      "puntoventa":  1,'  |
    & '      "emision":  "OTROS",'  |
    & '      "otrosComprobantes":  [{{'  |
    & '          "codigoTipoComprobante":  80,'  |
    & '          "comprobantes":  [{{'  |
    & '              "numeroComprobante":  1,'  |
    & '              "horaEmision":  "112520"'  |
    & '            }]'  |
    & '        }]'  |
    & '    }]'  |
    & '}')

MyObject                     GROUP
estado                         STRING(2), NAME('estado')
respuesta                      GROUP,DIM(2), NAME('respuesta')
puntoventa                       LONG, NAME('puntoventa')
emision                          STRING(8), NAME('emision')                             ! max string(5)
comprobantesFiscales             GROUP,DIM(2), NAME('comprobantesFiscales')             ! max array[1]
codigoTipoComprobante              LONG, NAME('codigoTipoComprobante')
comprobantes                       GROUP,DIM(2), NAME('comprobantes')                   ! max array[1]
monto                                LONG, NAME('monto')
numeroNodo                           LONG, NAME('numeroNodo')
numeroTransaccion                    LONG, NAME('numeroTransaccion')
numeroComprobante                    LONG, NAME('numeroComprobante')
horaEmision                          STRING(8), NAME('horaEmision')                     ! max string(6)
                                   END
                                 END
otrosComprobantes                GROUP,DIM(2), NAME('otrosComprobantes')                ! max array[1]
codigoTipoComprobante              LONG, NAME('codigoTipoComprobante')
comprobantes                       GROUP,DIM(2), NAME('comprobantes')                   ! max array[1]
                                 END
                               END
                             END

jParser                       cJSONFactory
jRoot                         &cJSON, AUTO
  CODE
  !- JSON -> Clarion
  IF jParser.ToGroup(sJson, MyObject, FALSE, | 
      '')

    !- Clarion -> JSON
    jRoot &= json::CreateObject(MyObject, TRUE, | 
      '[{"name":"*","IgnoreEmptyObject":true,"IgnoreEmptyArray":true,"EmptyString":"ignore"},' & | 
      '{"name":["comprobantesFiscales","codigoTipoComprobante","numeroNodo","numeroTransaccion","numeroComprobante","horaEmision","otrosComprobantes"], "JsonName":"*"}]')
    IF NOT jRoot &= NULL
      !- check result in DebugView
      printd(jRoot.ToString(TRUE))
      jRoot.Delete()
    END
  END

The mapper generates GROUP,DIM structures for json arrays. If you want the QUEUEs instead, do it yourself. I mean: replace groups with typed queue references

Hi Mike, Perfect!

I thought I had my ideas wrong.

Thanks so much!!