Bug #70580 Add function JSON_COUNT to count size of JSON document
Submitted: 9 Oct 2013 23:20 Modified: 4 Apr 2014 17:38
Reporter: Sveta Smirnova Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: JSON User-defined function ( UDF ) Severity:S4 (Feature request)
Version:0.2 OS:Any
Assigned to: Sveta Smirnova CPU Architecture:Any
Triage: Needs Triage: D5 (Feature request) / R2 (Low) / E3 (Medium)

[9 Oct 2013 23:20] Sveta Smirnova
Description:
Add function JSON_COUNT which will go through the JSON document and count number of childs of the root element.

How to repeat:
See description.
[19 Mar 2014 11:37] Sveta Smirnova
There are three possible ways to implement this function.

Scenario 1. Return depth of the JSON document. E.g. for document {"a": {"b": "c", "d": "e", "f": "g"}} result should be 3 and for document {"a": "b", "c": "d", "e": "f", "g": "h"} result should be 2. 

Scenario 2. Return number of elements in the whole document. In this case for document {"a": {"b": "c", "d": "e", "f": "g"}} result should be 5 and for document {"a": "b", "c": "d", "e": "f", "g": "h"} result should be 5.

Scenario 3. Return number of children of the root element. In this case for document {"a": {"b": "c", "d": "e", "f": "g"}} result should be 1 and for document {"a": "b", "c": "d", "e": "f", "g": "h"} result should be 4. This scenario can have optional argument: path to the root element. For example, JSON_COUNT('{"a": {"b": "c", "d": "e", "f": "g"}}', 'a') returns 3 and JSON_COUNT('{"a": {"b": "c", "d": "e", "f": "g"}}', 'a', 'b') returns 0.

Currently scenario 1 implemented as function JSON_DEPTH. We are still considering implementing other scenarios: 2 and 3. Please comment this report if you prefer one of them.
[4 Apr 2014 17:38] Sveta Smirnova
Posted by developer:
 
Fixed in version 0.3.2

Implemented scenario #3: Return number of children of the root element. In this case for document {"a": {"b": "c", "d": "e", "f": "g"}} result should be 1 and for document {"a": "b", "c": "d", "e": "f", "g": "h"} result should be 4. This scenario can have optional argument: path to the root element. For example, JSON_COUNT('{"a": {"b": "c", "d": "e", "f": "g"}}', 'a') returns 3 and JSON_COUNT('{"a": {"b": "c", "d": "e", "f": "g"}}', 'a', 'b') returns 0.