Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
stew_ia
Frequent Visitor

JSON with empty array

I'm working with a 3rd party REST API that returns an empty Results array when all of the data has been consumed.  "Results":[]   

This seems like it should be easy enough but it has me stumped.  I'm returning the Results to a loop that tests for Results being null which doesn't work,  but I'm not sure how to test for an empty array?

 

 

    GetActivities = (Index, access_token) =>
        let 
            Skip = Text.From(Index * RecordsPerPage),
            RawData = Web.Contents(BaseUrl,
                [
                    Headers=[
                        Authorization="Bearer " & access_token
                    ],
                    RelativePath="/crm/activity?$skip=" & Skip
                ]
            ),
            Source = Json.Document(RawData),
            Result1 = Source[Result]
            //res = try Source[Result] otherwise null,
            //Result3 = try res otherwise null
        in  Result1,

    access_token = GetToken(),
    TestRun = List.Generate ( 
        ()=>
            [Results = try GetActivities(0, access_token) otherwise null, Page = 0],
            each [Results] <> null and [Page]<5,
            each [Results = try GetActivities([Page] +1, access_token) otherwise null, Page = [Page]+1],
            each [Results]
    )
in
    TestRun

 

 Any pointers for a newbie would be appreciated.  Thanks in advance.  

1 ACCEPTED SOLUTION

That did it JirkaZ,  prolem solved.  

Results2 = if (Record.HasFields(Results1{0}, {"Id"})) then Results1 else null

View solution in original post

4 REPLIES 4
jggj
Frequent Visitor

How can I integrate it into the code? I'm too new

 
 
JirkaZ
Solution Specialist
Solution Specialist

@stew_ia Not sure from the top of my head but Json.Document typically returns a record, correct? So you could test the record with Record.HasFields perhaps?

That did it JirkaZ,  prolem solved.  

Results2 = if (Record.HasFields(Results1{0}, {"Id"})) then Results1 else null

Icey
Community Support
Community Support

Hi @stew_ia ,

 

Glad to hear that. Please accept your reply as a solution so that people who may have the same question can get the solution directly.

 

 

Best Regards,

Icey

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors