A way to do this would be to express the JSON structure as (path, value)
tuples and then use a map<json, json> to store them.

For example, your JSON above can be expressed as shown below where the path
is a list of keys/indices and the value is a scalar.

You could also concatenate the path elements and use them as a column key
instead. The advantage there is that you can do range queries against such
structures, and they will efficiently yield subtrees. E.g. a query for
"path > 'readings.1.' and path < 'readings.1.\uffff'" will yield the
appropriate rows.

ml

([u'events', 0, u'timestamp'], 1378686742465)

([u'events', 0, u'version'], 0.1)

([u'events', 0, u'type'], u'direction_change')

([u'events', 0, u'data', u'units'], u'miles')

([u'events', 0, u'data', u'direction'], u'NW')

([u'events', 0, u'data', u'offset'], 23)

([u'events', 1, u'timestamp'], 1378686742465)

([u'events', 1, u'version'], 0.1)

([u'events', 1, u'type'], u'altitude_change')

([u'events', 1, u'data', u'duration'], 18923)

([u'events', 1, u'data', u'rate'], 0.2)

([u'readings', 0, u'timestamp'], 1378686742465)

([u'readings', 0, u'value'], 20)

([u'readings', 0, u'rate_of_change'], 0.05)

([u'readings', 1, u'timestamp'], 1378686742466)

([u'readings', 1, u'value'], 22)

([u'readings', 1, u'rate_of_change'], 0.05)

([u'readings', 2, u'timestamp'], 1378686742467)

([u'readings', 2, u'value'], 21)

([u'readings', 2, u'rate_of_change'], 0.05)


On Wed, Sep 11, 2013 at 2:26 PM, Hartzman, Leslie <
leslie.d.hartz...@medtronic.com> wrote:

>  Hi,****
>
> ** **
>
> What would be the recommended way to deal with a complex JSON structure,
> short of storing the whole JSON as a value to a column? What options are
> there to store dynamic data like this?****
>
> ** **
>
> e.g.,****
>
> ** **
>
> {****
>
>   “ readings”: [****
>
>                 {****
>
>                        “value” : 20,****
>
>                       “rate_of_change” : 0.05,****
>
>                       “timestamp” :  1378686742465****
>
>                  },****
>
>                 {****
>
>                        “value” : 22,****
>
>                       “rate_of_change” : 0.05,****
>
>                       “timestamp” :  1378686742466****
>
>                  },****
>
>                 {****
>
>                        “value” : 21,****
>
>                       “rate_of_change” : 0.05,****
>
>                       “timestamp” :  1378686742467****
>
>                  }****
>
>   ],****
>
>   “events” : [****
>
>              {****
>
>                     “type” : “direction_change”,****
>
>                     “version” : 0.1,****
>
>                     “timestamp”: 1378686742465****
>
>                      “data” : {****
>
>                                           “units” : “miles”,****
>
>                                           “direction” : “NW”,****
>
>                                           “offset” : 23****
>
>                                       }****
>
>                },****
>
>              {****
>
>                     “type” : “altitude_change”,****
>
>                     “version” : 0.1,****
>
>                     “timestamp”: 1378686742465****
>
>                      “data” : {****
>
>                                           “rate”: 0.2,****
>
>                                           “duration” : 18923****
>
>                                       }****
>
>                 }****
>
>    ]****
>
> }****
>
> ** **
>
>                  ****
>
> [CONFIDENTIALITY AND PRIVACY NOTICE] Information transmitted by this email
> is proprietary to Medtronic and is intended for use only by the individual
> or entity to which it is addressed, and may contain information that is
> private, privileged, confidential or exempt from disclosure under
> applicable law. If you are not the intended recipient or it appears that
> this mail has been forwarded to you without proper authority, you are
> notified that any use or dissemination of this information in any manner is
> strictly prohibited. In such cases, please delete this mail from your
> records. To view this notice in other languages you can either select the
> following link or manually copy and paste the link into the address bar of
> a web browser: http://emaildisclaimer.medtronic.com
>

Reply via email to