Extracting JSON Arrays from inside Json Objects

Sannyasin Brahmanathaswami brahma at hindu.org
Fri Jul 15 22:03:23 EDT 2016


mark wrote:
 
BR: I actually think I like using a nested object
 
M: Right. I wasn't suggesting *not* using a nested object, just changing 
the format slightly:
 
{
     "file_id": "gr_1999-01-11_the-path-to-god",
            "file_size": null,
            "file_type": null,
            "format": null,
            "formats": {
                        "mp3": {
                                    "filename": "gr_1999-01-11_the-path-to-god.mp3",
                                    "isbn": null,
                                    "item_format_id": 1009,
                                    "item_id": 1217,
                                    "sale_date": null,
                                    "url": null
                        },
                        "pdf": {
                                    "filename": "this_is_my_filename.pdf",
[snip]
 
That way you pick out the information from the array as
 
aLiveCodeArray["formats"]["mp3"]["filename"]

-------------
That’s a tempting alternative.
 
scenarios vary depending on media_type
 
art/painting
art/drawing
art/vector 
 
records will all have associated item_format table records that current output like this:
 
"formats": [
        {
            "filename": "p6_rajam_ful.jpg",
            "format_name": "2531x4000",
            "isbn": null,
            "item_format_id": 43430,
            "item_id": 3268,
            "sale_date": "0000-00-00 00:00:00",
            "url": null
        },
        {
            "filename": "p6_rajam_lrg.jpg",
            "format_name": "911x1440",
            "isbn": null,
            "item_format_id": 43429,
            "item_id": 3268,
            "sale_date": "0000-00-00 00:00:00",
            "url": null
        },
        {
            "filename": "p6_rajam_med.jpg",
            "format_name": "316x500",
            "isbn": null,
            "item_format_id": 43428,
            "item_id": 3268,
            "sale_date": "0000-00-00 00:00:00",
            "url": null
        },
        {
            "filename": "p6_rajam_sml.jpg",
            "format_name": "523x390",
            "isbn": null,
            "item_format_id": 43427,
            "item_id": 3268,
            "sale_date": "0000-00-00 00:00:00",
            "url": null
        },
        {
            "filename": "p6_rajam_thm.jpg",
            "format_name": "149x111",
            "isbn": null,
            "item_format_id": 43426,
            "item_id": 3268,
            "sale_date": "0000-00-00 00:00:00",
            "url": null
        }
 
so this would translated into, using your model
 
{"file_id": "p6_rajam",
          "formats": [
        {
   "2531x4000": {
            "filename": "p6_rajam_ful.jpg",
             "isbn": null,
            "item_format_id": 43430,
            "item_id": 3268,
            "sale_date": "0000-00-00 00:00:00",
            "url": null
        },
   "911x1440"
             {
            "filename": "p6_rajam_lrg.jpg",
             "isbn": null,
            "item_format_id": 43429,
            "item_id": 3268,
            "sale_date": "0000-00-00 00:00:00",
            "url": null
        },
       
 
Actually there is some utility in that form. The second element in the array becomes intelligible vs "[1]"  and would mean less parsing to find what we want, typically "format_name" does in fact tell us what file we want, in the case of art, the rect is "mission critical" on making a selection for any given view context, similarly for books (epub or pdf)
 
thanks! 
 
 






More information about the use-livecode mailing list