Reading JSON from *.json File

A Score Level 1

Hello All,

 

I have a JSON file from which i need to read data. The file is not in any particular format and may have about 45,000 lines of data. 

To read document file the the only function i can find is readtextfromfile but problem with this function (in my scenario) is its converting JSON into a single text string

and because of which i am not able to use index function on it. I want data in any format.

 

We had a different input method before, Instead of JSON file we received data from DB so i was getting data in List of Variant instead of text.

 

 

                        

 

 

 

 

 

 

  Discussion posts and replies are publicly visible

Parents
  • I think this is what you're looking for:

    Assuming cons!SBX_DOCUMENT_JSON_EXAMPLE is a constant of type document, and the content of that document is:

    {
    "age":100,
    "name":"xyz.com",
    "messages":["msg 1","msg 2","msg 3"]
    }


     

    THEN

    index(
      {a!fromJson(
        {fn!readtextfromfile(cons!SBX_DOCUMENT_JSON_EXAMPLE, true())}
      )},
      "messages"
    )


    RETURNS:
    List of Text String: 3 items
        "msg 1"
        "msg 2"
        "msg 3"

    AND

    index(
      {a!fromJson(
        {fn!readtextfromfile(cons!SBX_DOCUMENT_JSON_EXAMPLE, true())}
      )},
      "age"
    )


    RETURNS:
    100

  • 0
    A Score Level 1
    in reply to Robert Shankin
    I tried this but got this error.
    Note: I used the same JSON you have added above

    Expression evaluation error at function a!fromJson [line 2]: Error evaluating function fn!fromjson_appian_internal : The jsonText parameter was not valid JSON. Received: { "age":100, "name":"xyz.com", "messages":["msg 1","msg 2","msg 3"] }
Reply Children