I never thought of it, but supporting an append semantic in the “jsonLanguage” I created is an excellent idea. After all this semantic (array[]) is already used in other languages like PHP, why not implementing it here also.
From the version 0.6.0 Node-Json-DB support this new semantic to append an element to an array:
//You can also easily append new item to an existing array //This set the next index with {obj: 'test'} db.push("/arraytest/myarray[]", {obj:'test'}, true); //The append feature can be used in conjuction with properties //This will set the next index as an object {myTest: 'test'} db.push("/arraytest/myarray[]/myTest", 'test', true);
I’m thinking of adding more semantic support to the array like a possibility to get the last item with “array[-1]” etc …
I also found documentation on JsonPath. I’m thinking of implementing some of it in a new method path. It would be only used for querying the data, not for pushing it. Or maybe the support will be included directly into the existing method. I still have to think about it and if it wouldn’t make this small library too big.
Leave a Reply