All Things WinBatch > WinBatch

**************** New JSON Extender (Experimental) *******************

<< < (3/7) > >>

td:
I realize that is just an example to make a point but the  JSON object

{
parent: {
               key1:value
               key2:value }
}

parent: {
               key1:value
               key2:value }
}


}

does validate and parse but since you can't have two keys with the same name at the same level within a JSON object the second object overwrites the first. This expected behavior is shown by online JSON validators. In order to do what your example purposes would require placing the objects in a JSON array.

td:
A new (already) version of the extender is in the download area the link is the same.

https://files.winbatch.com/downloads/wb/ilcjs44i.zip

This version addresses the parameter validation issue and adds some neglected verbiage in the help file.

The feedback has been tremendous.  Taking the time to look at the extender is much appreciated. Please feel free to make additional comments and suggestions.

stanl:

--- Quote from: td on September 10, 2021, 09:43:16 am ---In order to do what your example purposes would require placing the objects in a JSON array.

--- End quote ---


Understood. So assuming I was scraping consistent REST results and knew the data was a Json array with a 'parent' key, no problem. But [perhaps a holy grail] to determine that on inspection of the data - first time.

td:
Not sure I understand what you are suggesting but you can use the jsValueType function to determine the JSON type of an element in a JSON tree of objects include JSON containers, i.e., objects and arrays. You can collect the types of all the elements at once using jsKeyPath to get all paths and jsValueType to get the type of each key in the path and the type of each element in any arrays in the object or objects.

stanl:

--- Quote from: td on September 10, 2021, 02:49:18 pm ---Not sure I understand what you are suggesting but you can use the jsValueType function to determine the JSON type of an element in a JSON tree of objects include JSON containers, i.e., objects and arrays. You can collect the types of all the elements at once using jsKeyPath to get all paths and jsValueType to get the type of each key in the path and the type of each element in any arrays in the object or objects.

--- End quote ---


I missed the "" to get all Paths. A little spoiled with Jim's use of 'tree'..  ended up writing a udf crTree() which does exactly what I need. I'll end up referring to branches or limbs rather than paths/keys :o  but the extender is really slick!

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version