Working with JSON - Forum - OpenEdge Development - Progress Community
 Forum

Working with JSON

This question is answered

I'm struggling a bit with a JSON produced by Elasticsearch. What I want to do is parse the JSON-string and output some data based on values in the document. 

First I tried to match a dataset to the structure but I failed. Having worked quite a lot with 3rd party XML I wasn't surprised. So looking at other options I started working with the Progress.JSON collection but I'm not getting anywhere. Since I'm unsused to OOABL I'm unsure if it's me or if functionality is missing. I can't really get any data out of it.

This is what I've tried so far:

USING Progress.Json.ObjectModel.*.

DEFINE VARIABLE lResJSONCode AS LONGCHAR          NO-UNDO.
DEFINE VARIABLE myParser     AS ObjectModelParser NO-UNDO.
DEFINE VARIABLE myConstruct  AS JsonConstruct     NO-UNDO.

COPY-LOB FROM FILE "c:\temp\json.json" TO lResJSONCode CONVERT TARGET CODEPAGE "utf-8".

myParser = NEW ObjectModelParser( ).
myConstruct = myParser:Parse(lResJSONCode).

/** Now what? **/
/* This doesn't work 
MESSAGE myConstruct:cluster_name VIEW-AS ALERT-BOX.
*/
DELETE OBJECT myConstruct.
DELETE OBJECT myParser.

Doing myConstruct:writeFile("c:\temp\jsonoutput.json") actually creates a file with the right content so I know I at least have something to work with. 

A J-DOCUMENT like the X-DOCUMENT handle would be nice by the way...

Hints?

Verified Answer
  • we use json like this : written in the gmail IDE ;)

    USING Progress.Json.ObjectModel.*.

    DEFINE VARIABLE lResJSONCode AS LONGCHAR NO-UNDO.
    DEFINE VARIABLE myParser AS ObjectModelParser NO-UNDO.
    DEFINE VARIABLE myObject AS JsonObject NO-UNDO.

    COPY-LOB FROM FILE "c:\temp\json.json" TO lResJSONCode CONVERT TARGET
    CODEPAGE "utf-8".

    myParser = NEW ObjectModelParser( ).
    myObject = myParser:Parse(lResJSONCode).

    MESSAGE myObject:GetCharacter("cluster_name") VIEW-AS ALERT-BOX.

    DELETE OBJECT myObject .
    DELETE OBJECT myParser.

    On 21 February 2014 11:46, Jens Dahlin
    wrote:
    > Working with JSON
    > Thread created by Jens Dahlin
    >
    > I'm struggling a bit with a JSON produced by Elasticsearch. What I want to
    > do is parse the JSON-string and output some data based on values in the
    > document.
    >
    > First I tried to match a dataset to the structure but I failed. Having
    > worked quite a lot with 3rd party XML I wasn't surprised. So looking at
    > other options I started working with the Progress.JSON collection but I'm
    > not getting anywhere. Since I'm unsused to OOABL I'm unsure if it's me or if
    > functionality is missing. I can't really get any data out of it.
    >
    > This is what I've tried so far:
    >
    > USING Progress.Json.ObjectModel.*.
    >
    > DEFINE VARIABLE lResJSONCode AS LONGCHAR NO-UNDO.
    > DEFINE VARIABLE myParser AS ObjectModelParser NO-UNDO.
    > DEFINE VARIABLE myConstruct AS JsonConstruct NO-UNDO.
    >
    > COPY-LOB FROM FILE "c:\temp\json.json" TO lResJSONCode CONVERT TARGET
    > CODEPAGE "utf-8".
    >
    > myParser = NEW ObjectModelParser( ).
    > myConstruct = myParser:Parse(lResJSONCode).
    >
    > /** Now what? **/
    > /* This doesn't work
    > MESSAGE myConstruct:cluster_name VIEW-AS ALERT-BOX.
    > */
    > DELETE OBJECT myConstruct.
    > DELETE OBJECT myParser.
    >
    > Doing myConstruct:writeFile("c:\temp\jsonoutput.json") actually creates a
    > file with the right content so I know I at least have something to work
    > with.
    >
    > A J-DOCUMENT like the X-DOCUMENT handle would be nice by the way...
    >
    > Hints?
    >
    > Stop receiving emails on this subject.
    >
    > Flag this post as spam/abuse.



    --
    Julian Lyndon-Smith
    IT Director,
    dot.r
    http://www.dotr.com

    "The bitterness of poor quality remains long after the sweetness of
    low price is forgotten"

    Follow dot.r on http://twitter.com/DotRlimited
All Replies
  • we use json like this : written in the gmail IDE ;)

    USING Progress.Json.ObjectModel.*.

    DEFINE VARIABLE lResJSONCode AS LONGCHAR NO-UNDO.
    DEFINE VARIABLE myParser AS ObjectModelParser NO-UNDO.
    DEFINE VARIABLE myObject AS JsonObject NO-UNDO.

    COPY-LOB FROM FILE "c:\temp\json.json" TO lResJSONCode CONVERT TARGET
    CODEPAGE "utf-8".

    myParser = NEW ObjectModelParser( ).
    myObject = myParser:Parse(lResJSONCode).

    MESSAGE myObject:GetCharacter("cluster_name") VIEW-AS ALERT-BOX.

    DELETE OBJECT myObject .
    DELETE OBJECT myParser.

    On 21 February 2014 11:46, Jens Dahlin
    wrote:
    > Working with JSON
    > Thread created by Jens Dahlin
    >
    > I'm struggling a bit with a JSON produced by Elasticsearch. What I want to
    > do is parse the JSON-string and output some data based on values in the
    > document.
    >
    > First I tried to match a dataset to the structure but I failed. Having
    > worked quite a lot with 3rd party XML I wasn't surprised. So looking at
    > other options I started working with the Progress.JSON collection but I'm
    > not getting anywhere. Since I'm unsused to OOABL I'm unsure if it's me or if
    > functionality is missing. I can't really get any data out of it.
    >
    > This is what I've tried so far:
    >
    > USING Progress.Json.ObjectModel.*.
    >
    > DEFINE VARIABLE lResJSONCode AS LONGCHAR NO-UNDO.
    > DEFINE VARIABLE myParser AS ObjectModelParser NO-UNDO.
    > DEFINE VARIABLE myConstruct AS JsonConstruct NO-UNDO.
    >
    > COPY-LOB FROM FILE "c:\temp\json.json" TO lResJSONCode CONVERT TARGET
    > CODEPAGE "utf-8".
    >
    > myParser = NEW ObjectModelParser( ).
    > myConstruct = myParser:Parse(lResJSONCode).
    >
    > /** Now what? **/
    > /* This doesn't work
    > MESSAGE myConstruct:cluster_name VIEW-AS ALERT-BOX.
    > */
    > DELETE OBJECT myConstruct.
    > DELETE OBJECT myParser.
    >
    > Doing myConstruct:writeFile("c:\temp\jsonoutput.json") actually creates a
    > file with the right content so I know I at least have something to work
    > with.
    >
    > A J-DOCUMENT like the X-DOCUMENT handle would be nice by the way...
    >
    > Hints?
    >
    > Stop receiving emails on this subject.
    >
    > Flag this post as spam/abuse.



    --
    Julian Lyndon-Smith
    IT Director,
    dot.r
    http://www.dotr.com

    "The bitterness of poor quality remains long after the sweetness of
    low price is forgotten"

    Follow dot.r on http://twitter.com/DotRlimited
  • Thank you! I had to cast the object to a JsonObject, otherwise it worked.

    myObject = CAST(myParser:Parse(lResJSONCode), PROGRESS.Json.ObjectModel.JsonObject).

    But what if the node is another JSON Object/more nodes? There doesn't seem to be a GetJsonObject method?

  • there is ;)

    GetJsonObject(INPUT CHARACTER) - Progress.Json.ObjectModel.JsonObject
    Returns Progress.Json.ObjectModel.JsonObject value.

    what version of progress are you on ? 11.3.2 has the GetJsonObject
    method on a JsonObject

    On 21 February 2014 12:08, Jens Dahlin
    wrote:
    > RE: Working with JSON
    > Reply by Jens Dahlin
    >
    > Thank you! I had to cast the object to a JsonObject, otherwise it worked.
    >
    > myObject = CAST(myParser:Parse(lResJSONCode),
    > PROGRESS.Json.ObjectModel.JsonObject).
    >
    > But what if the node is another JSON Object/more nodes? There doesn't seem
    > to be a GetJsonObject method?
    >
    > Stop receiving emails on this subject.
    >
    > Flag this post as spam/abuse.



    --
    Julian Lyndon-Smith
    IT Director,
    dot.r
    http://www.dotr.com

    "The bitterness of poor quality remains long after the sweetness of
    low price is forgotten"

    Follow dot.r on http://twitter.com/DotRlimited
  • I'm on 11.2 and apparently its there. It's just missing in the documentation...

  • Never trust the documentation:)

    On 21 Feb 2014 12:22, "Jens Dahlin" <bounce-Jensairtoursse@community.progress.com> wrote:
    Reply by Jens Dahlin

    I'm on 11.2 and apparently its there. It's just missing in the documentation...

    Stop receiving emails on this subject.

    Flag this post as spam/abuse.