# I can't parse the json with the cJson class. Do I have the group well defined?

**URL:** <https://clarionhub.com/t/i-cant-parse-the-json-with-the-cjson-class-do-i-have-the-group-well-defined/6851>\
**Category:** questions\
**Tags:** cjson, json\
**Created:** [December 15, 2023, 2:56am UTC](https://clarionhub.com/t/i-cant-parse-the-json-with-the-cjson-class-do-i-have-the-group-well-defined/6851 "2023-12-15T02:56:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlos.pizzi](https://clarionhub.com/user_avatar/clarionhub.com/carlos.pizzi/32/2633_2.png) [@carlos.pizzi](https://clarionhub.com/u/carlos.pizzi)\
**Post date:** [December 15, 2023, 2:56am UTC](https://clarionhub.com/t/i-cant-parse-the-json-with-the-cjson-class-do-i-have-the-group-well-defined/6851/1 "2023-12-15T02:56:36Z")

</div>

Good night,

I am trying to obtain the values of the json that I indicate, but for some fields I do not get the result, such as: ns2:dProtConsLote or ns2:dCodRes

Where is my mistake. Do I have the group well defined?

I have the following json, which I read from a file:

```auto
{
    "success": true,
    "environment": "test",
    "xml": []
    "msg": {
        "ns2:rResEnviLoteDe": {
            "$": {
                "xmlns:ns2": "http://ekuatia.set.gov.py/sifen/xsd"
            },
            "ns2:dFecProc": "2023-12-14T07:12:48-03:00",
            "ns2:dCodRes": "0300",
            "ns2:dMsgRes": "Lote recibido con éxito",
            "ns2:dProtConsLote": "11453601354823256",
            "ns2:dTpoProces": "0"
        },
        "id": "647695277"
    }
}

```

the definition of the group

```auto
GJson Group
success STRING(5)
environment STRING(255),Name('environment')
qxml &QUEUE,Name('xml')
G2 Group,Name('msg')
G3 Group,Name('ns2:rResEnviLoteDe')
G4 Group,Name('$')
xmlns:ns2 STRING(255),Name('xmlns:ns2')
                                    End
ns2:dFecProc STRING(255),Name('ns2:dFecProc')
ns2:dCodRes STRING(255),Name('ns2:dCodRes')
ns2:dMsgRes STRING(255),Name('ns2:dMsgRes')
ns2:dProtConsLote STRING(255),Name('ns2:dProtConsLote')
ns2:dTpoProces STRING(255),Name('ns2:dTpoProces')
                                End
id STRING(255),Name('id')
                            End
                        End

qxml QUEUE
Str STRING(20000)
                        END

```

my code

```auto
        root &= jsonFactory.ParseFile('respuesta.json')
        IF root &= NULL
            !error
            MESSAGE('Syntax error near: '& jsonFactory.GetError() &'|at position '& jsonFactory.GetErrorPosition())
            RETURN
        END
  
        
        
        !see the resulting json
        json::DebugInfo(root.ToString(TRUE)) !formatted outpur
        !MESSAGE(root.ToString(TRUE)) !formatted outpur
            
        GJson.qxml &= qxml
        
        IF NOT jsonFactory.ToGroup(root.ToString(), GJson, FALSE, '[{{"name":"xml", "instance":'& INSTANCE(qxml, THREAD()) &'}]')
            MESSAGE('error: ' & jsonFactory.GetError())
            RETURN
        END      
        
        MESSAGE('GJson.success: ' & CLIP(LEFT(GJson.success)) | 
            & '|id: ' & CLIP(LEFT(GJson.G2.id)) | 
            & '|environment: ' & CLIP(LEFT(GJson.environment)) | 
            & '|ns2:dCodRes: ' & CLIP(LEFT(GJson.G2.G3.ns2:dCodRes)) | 
            & '|ns2:dProtConsLote: ' & CLIP(LEFT(GJson.G2.G3.ns2:dProtConsLote)) |
            & '|xmlns:ns2: ' & CLIP(LEFT(GJson.G2.G3.G4.xmlns:ns2)) |     
            & '|records xml: ' & CLIP(LEFT(records(qxml))) |     
            )      
       

        
        !dispose all cJSON objects at once
        root.Delete()

```

 ![imagen](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/2X/7/7cdc7abf593881efd9207fbc2d828842059e4ba5.png)

thank you very much for your help

---

<div class="post-metadata">

**Author:** ![seanh](https://clarionhub.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@seanh](https://clarionhub.com/u/seanh)\
**Post date:** [December 15, 2023, 3:30am UTC](https://clarionhub.com/t/i-cant-parse-the-json-with-the-cjson-class-do-i-have-the-group-well-defined/6851/2 "2023-12-15T03:30:00Z")

</div>

I use capesofts jcode website generator  
[https://www.capesoft.com/jFilesCode](https://www.capesoft.com/jFilesCode)  
Although it does appear to have trouble with what you have there

---

<div class="post-metadata">

**Author:** ![seanh](https://clarionhub.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@seanh](https://clarionhub.com/u/seanh)\
**Post date:** [December 15, 2023, 3:45am UTC](https://clarionhub.com/t/i-cant-parse-the-json-with-the-cjson-class-do-i-have-the-group-well-defined/6851/3 "2023-12-15T03:45:30Z")

</div>

Hmm Needed a , on the end of the xml line, then it comes out with this:

```auto
element Group,Name('element')
success Byte,Name('success | boolean')
environment STRING(255),Name('environment')
xml String(240) ,Dim(10),Name('xml')
msg Group,Name('msg')
ns2:rResEnviLoteDe Group,Name('ns2:rResEnviLoteDe')
                               Group,Name('$')
xmlns:ns2 STRING(255),Name('xmlns:ns2')
                               End
ns2:dFecProc STRING(255),Name('ns2:dFecProc')
ns2:dCodRes STRING(255),Name('ns2:dCodRes')
ns2:dMsgRes STRING(255),Name('ns2:dMsgRes')
ns2:dProtConsLote STRING(255),Name('ns2:dProtConsLote')
ns2:dTpoProces STRING(255),Name('ns2:dTpoProces')
                             End
id STRING(255),Name('id')
                           End
                         End

json jsonClass

  CODE
  
  !-- Load From StringTheory object into Structure---
  json.start()
  json.SetTagCase(jf:CaseAsIs)
  json.Load(element,SomeLoadString) ! Load From a StringTheory object

```

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [December 15, 2023, 9:47am UTC](https://clarionhub.com/t/i-cant-parse-the-json-with-the-cjson-class-do-i-have-the-group-well-defined/6851/4 "2023-12-15T09:47:38Z")

</div>

Colons in field names is the problem. You can define the matches for names in the options like this:

```auto
sRules STRING(2048), AUTO

    sRules = '' |
      & '[{{"name":"xml", "instance":'& INSTANCE(qxml, THREAD()) & '},' |
      & '{{"name":"rResEnviLoteDe","jsonname":"ns2:rResEnviLoteDe"},' |
      & '{{"name":"ns2","jsonname":"xmlns:ns2"},' |
      & '{{"name":"dFecProc","jsonname":"ns2:dFecProc"},' |
      & '{{"name":"dCodRes","jsonname":"ns2:dCodRes"},' |
      & '{{"name":"dMsgRes","jsonname":"ns2:dMsgRes"},' |
      & '{{"name":"dProtConsLote","jsonname":"ns2:dProtConsLote"},' |
      & '{{"name":"dTpoProces","jsonname":"ns2:dTpoProces"}]'
    jRoot.ToGroup(GJson, FALSE, sRules)

```

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/7/772cad1ed8439f46c8091d90f9c785d568a3c889.png)

---

<div class="post-metadata">

**Author:** ![carlos.pizzi](https://clarionhub.com/user_avatar/clarionhub.com/carlos.pizzi/32/2633_2.png) [@carlos.pizzi](https://clarionhub.com/u/carlos.pizzi)\
**Post date:** [December 15, 2023, 2:44pm UTC](https://clarionhub.com/t/i-cant-parse-the-json-with-the-cjson-class-do-i-have-the-group-well-defined/6851/5 "2023-12-15T14:44:00Z")

</div>

Oh! very interesting!! Thank you so much !!
