Extract directly from BLOB is now complete and appears to work.

FossilOrigin-Name: 3de58ec99444b16dfcda1e226420e2343450b77abd3faf33a88b6d18339ef17c
diff --git a/manifest b/manifest
index c1019d9..f6be12b 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Miscellaneous\sbugs\sfixed.
-D 2023-09-28T17:07:43.443
+C Extract\sdirectly\sfrom\sBLOB\sis\snow\scomplete\sand\sappears\sto\swork.
+D 2023-09-28T17:23:46.244
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -670,7 +670,7 @@
 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
-F src/json.c 946e0bbc5070db333a370e2f7b806ad07d2e9fb93d057cf52a9e5fb58fd43768
+F src/json.c 7e68346bfc4f030e454c68751ab7082af52b9925ff28bff88eef03258e486d7c
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
@@ -2123,8 +2123,8 @@
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 8c82576176539c4d132b14d46adbf31366c4bcaa59a61dd639dc9cc308fe8825
-R e6233e4f5d16d81e42c25a8ff039c998
+P 5c0815fa2e422d81198a43a2c04a022e319fcbcadfd4be4437f2e663892ca26b
+R 0d79abb184ac0c9db2e32b0ee612448c
 U drh
-Z beeeb6a9ecf43431f000f927a20c9a15
+Z dfb6861bdfa5add7990cbc313b482bb0
 # Remove this line to create a well-formed Fossil manifest.
diff --git a/manifest.uuid b/manifest.uuid
index 5bf7e31..6de749e 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-5c0815fa2e422d81198a43a2c04a022e319fcbcadfd4be4437f2e663892ca26b
\ No newline at end of file
+3de58ec99444b16dfcda1e226420e2343450b77abd3faf33a88b6d18339ef17c
\ No newline at end of file
diff --git a/src/json.c b/src/json.c
index 322fbc5..e43240c 100644
--- a/src/json.c
+++ b/src/json.c
@@ -3508,6 +3508,21 @@
 }
 
 /*
+** Given that a JSONB_ARRAY object starts at offset i, return
+** the number of entries in that array.
+*/
+static u32 jsonbArrayCount(JsonParse *pParse, u32 iRoot){
+  u32 n, sz, i, iEnd;
+  u32 k = 0;
+  n = jsonbPayloadSize(pParse, iRoot, &sz);
+  iEnd = iRoot+n+sz;
+  for(i=iRoot+n; i<iEnd; i+=sz+n, k++){
+    n = jsonbPayloadSize(pParse, i, &sz);
+  }
+  return k;
+}
+
+/*
 ** Error returns from jsonLookupBlobStep()
 */
 #define JSON_BLOB_ERROR      0xffffffff
@@ -3579,6 +3594,9 @@
     }
     if( j>iEnd ) return JSON_BLOB_ERROR;
   }else if( zPath[0]=='[' ){
+    x = pParse->aBlob[iRoot] & 0x0f;
+    if( x!=JSONB_ARRAY )  return JSON_BLOB_NOTFOUND;
+    n = jsonbPayloadSize(pParse, iRoot, &sz);
     k = 0;
     i = 1;
     while( sqlite3Isdigit(zPath[i]) ){
@@ -3586,49 +3604,28 @@
       i++;
     }
     if( i<2 || zPath[i]!=']' ){
-#if 0
       if( zPath[1]=='#' ){
-        JsonNode *pBase = pRoot;
-        int iBase = iRoot;
-        if( pRoot->eType!=JSON_ARRAY ) return 0;
-        for(;;){
-          while( j<=pBase->n ){
-            if( (pBase[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ) i++;
-            j += jsonNodeSize(&pBase[j]);
-          }
-          if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
-          if( pParse->useMod==0 ) break;
-          assert( pBase->eU==2 );
-          iBase = pBase->u.iAppend;
-          pBase = &pParse->aNode[iBase];
-          j = 1;
-        }
-        j = 2;
+        k = jsonbArrayCount(pParse, iRoot);
+        i = 2;
         if( zPath[2]=='-' && sqlite3Isdigit(zPath[3]) ){
           unsigned int x = 0;
-          j = 3;
+          i = 3;
           do{
-            x = x*10 + zPath[j] - '0';
-            j++;
-          }while( sqlite3Isdigit(zPath[j]) );
-          if( x>i ) return 0;
-          i -= x;
+            x = x*10 + zPath[i] - '0';
+            i++;
+          }while( sqlite3Isdigit(zPath[i]) );
+          if( x>k ) return 0;
+          k -= x;
         }
-        if( zPath[j]!=']' ){
+        if( zPath[i]!=']' ){
           *pzErr = zPath;
-          return 0;
+          return JSON_BLOB_PATHERROR;
         }
       }else{
         *pzErr = zPath;
-        return 0;
+        return JSON_BLOB_PATHERROR;
       }
-#endif
-      *pzErr = zPath;
-      return JSON_BLOB_PATHERROR;
     }
-    x = pParse->aBlob[iRoot] & 0x0f;
-    if( x!=JSONB_ARRAY )  return JSON_BLOB_NOTFOUND;
-    n = jsonbPayloadSize(pParse, iRoot, &sz);
     j = iRoot+n;
     iEnd = j+sz;
     while( j<iEnd ){