JSON UDFs: is it hard to type keys?

Currently, if you want to search a key using JSON UDFs you have to specify each its part as a separate argument to the function: JSON_CONTAINS_KEY(doc, 'root', 'child', 'child of child', 'child of child of child', etc.....). This way of working with parameters is easy for developer, less error-prone, but can be not very beautiful.

I was suggested by some of users to change it to '/parent/child/child-of-child/...' or to 'parent:child:child-of-child:...' There are, probably, can be other suggestions. What do you like the best? How do you feel about current style with separate argument for each key element? Should we change or extend this syntax?

Comments:

Sveta,

The answer is very simple: don't invent your own syntax. IMHO you should use one of two possibilities:

1. The obvious one: JSON notation (you are parsing JSON, right?). JSON is JavaScript Object Notation, and so the way to get a JS object value is 'parent.child.grandChild'. If there's an array involved then something like 'parent.child[4].someAttribute'

2. XPath: '/parent/child/grandChild'. XPath is already used by MySQL's XML function ExtractValue(), and is a great way of getting JSON data

Posted by Shlomi Noach on December 17, 2013 at 08:11 PM MSK #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Working blog of Sveta Smirnova - MySQL Senior Principal Support Engineer working in Bugs Analysis Support Group

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today