From 8607a7f516e3c3e75871c2c08ec82430c1aab25f Mon Sep 17 00:00:00 2001
From: Markus Mittendrein <git@maxmitti.tk>
Date: Sat, 15 Aug 2020 18:23:49 +0200
Subject: [PATCH 1/2] Fix handling of empty arrays and objects

---
 JSONStream.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/JSONStream.php b/JSONStream.php
index 433dd1e..089eaf5 100644
--- a/JSONStream.php
+++ b/JSONStream.php
@@ -47,6 +47,10 @@ class JSONStream
         $this->offset++;
         $this->skipWhitespace();
         $st = $this->buffer[$this->offset] === '}' ? 2 : 1;
+        if ($st == 2)
+        {
+            $this->offset++;
+        }
         $this->in[] = [ $st, self::OBJ, NULL, false ];
     }
 
@@ -64,6 +68,10 @@ class JSONStream
         $this->offset++;
         $this->skipWhitespace();
         $st = $this->buffer[$this->offset] === ']' ? 2 : 1;
+        if ($st == 2)
+        {
+            $this->offset++;
+        }
         $this->in[] = [ $st, self::ARR, NULL, false ];
     }
 
-- 
2.30.2


From ae3cc7d8837c981bad8671b94387cab13f98971a Mon Sep 17 00:00:00 2001
From: Markus Mittendrein <git@maxmitti.tk>
Date: Sat, 15 Aug 2020 18:25:29 +0200
Subject: [PATCH 2/2] Only return false in readValue when isEnded is already
 true

---
 JSONStream.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/JSONStream.php b/JSONStream.php
index 089eaf5..6d7f5c1 100644
--- a/JSONStream.php
+++ b/JSONStream.php
@@ -127,7 +127,7 @@ class JSONStream
             $v = $this->readToken();
         } while (count($this->in) > $n);
         $value = $v;
-        return ($this->in[count($this->in)-1][0] == 1);
+        return true;
     }
 
     public function unreadBuffer()
-- 
2.30.2