How to read large Json File

Hello ,

I am trying to read a JSON file which contains almost 24570 line but eggplant is able to read only 3973 lines . could please suggest how to read whole json file.

Thanks in advance

Hey @bhaavan,
Can you post your code? Do you use the Jsonvalue() or Jsonformat Function?
Cheers,
Karsten

Hello @Karsten ,
Thanks for you reply , we are using below mentioned code .

set TCData to JSONValue(file(“Z:\Data\Testdata.json”))

Hi @bhaavan ,
What do you mean, just 3973 lines? Are you attempting to print it on your console?

Hey @bhaavan,
I am not aware that we have a character or line limit for json files.

Our current idea is that the json format is not correct. Did you check the json that its actually a correct json format? You can use a notepad++ or an online json beautifier which will show you any flaws within the file structure in case thats the same.

Would you mind sharing the particular json with us via our support or via a link if its sharable? When shared via support kindly ask you to add this forum link and mention my name that the file gets distributed to me.
Cheers,
Karsten

Hello @Surath ,
Yes I am trying read that particular file and printing it on console

Hello @Karsten ,

Sorry I am not supposed to share JSON file , I have check JSON format in online , it says valid JSON

Are you are looking for the 29K+ lines to be printed in the console?
Can you just try access a element from last and see is it reading?

thanks surath it worked ,

A follow up question
How to edit or replace value in JSON file

Hi @bhaavan
Here’s an entry-level code you may try.

//Create a Json File
put {id:“1”,Name:“Jhon”,IdNumber:“101”} into ListOfValues
put JSONFormat of ListOfValues into file ResourcePath(“Test.Json”)

//Modify the Json File
put JSONValue of file ResourcePath(“Test.Json”) into Data
put “2” into Data.Id
put “102” into Data.IdNumber
put “King” into Data.Name
put JSONFormat of Data into file ResourcePath(“Test.Json”)
Log file ResourcePath(“Test.Json”)

Hello @Surath ,
Thanks for your reply, My json file looks bit different I have pasted my json code below could please look into that .
Problem : In below JSON I have to change Name from david to Robbert in BINEntryID : 2
could please help me with the code .

It would be very helpful , if you can share code .

JSON

{
“BINEntries”: [

{
        "BINEntryID": 1,
    "Name":"Jhon",
    "age":25,
        "Gender":"Male"

},

 {
        "BINEntryID": 2,
    "Name":"David",
    "age":43,
        "Gender":"Male"

},

 {
        "BINEntryID": 3,
    "Name":"Leo",
    "age":19,
        "Gender":"Male"

},

 {
        "BINEntryID": 4,
    "Name":"Robin",
    "age":35,
        "Gender":"Male"

},

    {
        "BINEntryID": 5,
    "Name":"Rebacca",
    "age":24,
        "Gender":"Female"

        }
]

}

I hope this works for you.

//Modify the Json File
to ChangeName entryID, entryName – Enter the entryId to which you wish to alter the name, and entryName is the new name.
put JSONValue of file ResourcePath(“bhaavan.Json”) into Data – change the json file to your actual json file
repeat with each item of Data.BINEntries
if (it.BINEntryID) is entryID then
put entryName into it.Name
put it into item repeatIndex() of Data.BINEntries
exit repeat
end if
end repeat
put JSONFormat of Data into file ResourcePath(“bhaavan.Json”)
end ChangeName

ChangeName 2,“Robert” --Calling Handler

Here is a slightly shorter version of Surath’s ChangeName handler using each expression instead of a repeat loop.

to ChangeName entryID, entryName -- Enter the entryId to which you wish to alter the name, and entryName is the new name.
    put JSONValue of file ResourcePath(“bhaavan.Json”) into Data -- change the json file to your actual json file
    Replace properties {Name: entryName} of each item of Data.BINEntries where each.BINEntryID is entryID
    put JSONFormat of Data into file ResourcePath(“bhaavan.Json”)
end ChangeName
1 Like