1

I have tried a variety of things, to parse the following json and it has not been working for me. It returns blank. How would I for example, retrieve and store as a variable the SourceFile name "example.jpg" or the filesize? Thanks!

[
    {
        "SourceFile": "example.jpg",
        "ExifTool": {
            "ExifToolVersion": 9.04
        },
        "File": {
            "FileName": "example.jpg",
            "Directory": ".",
            "FileSize": "323 kB",
            "FileModifyDate": "2013:10:17 11:10:21-04:00",
            "FileAccessDate": "2013:12:10 11:47:49-05:00",
            "FilePermissions": "rwxrwxrwx",
            "FileType": "JPEG",
            "MIMEType": "image/jpeg",
            "ImageWidth": 1000,
            "ImageHeight": 658,
            "EncodingProcess": "Progressive DCT, Huffman coding",
            "BitsPerSample": 8,
            "ColorComponents": 3,
            "YCbCrSubSampling": "YCbCr4:4:4 (1 1)"
        },
        "JFIF": {
            "JFIFVersion": 1.02,
            "ResolutionUnit": "None",
            "XResolution": 100,
            "YResolution": 100
        },
        "Ducky": {
            "Quality": "95%"
        },
        "XMP": {
            "XMPToolkit": "Adobe XMP Core 4.2.2-c063 53.352624, 2008/07/30-18:12:18 ",
            "Make": "Canon",
            "Model": "Canon EOS 40D",
            "XResolution": 240,
            "YResolution": 240,
            "ResolutionUnit": "inches",
            "ExifVersion": "0221",
            "ExposureTime": "1/1000",
            "ShutterSpeedValue": "1/1000",
            "FNumber": 8,
            "ApertureValue": 8,
            "ExposureProgram": "Aperture-priority AE",
            "DateTimeOriginal": "2013:09:27 13:03:40.00+01:00",
            "DateTimeDigitized": "2013:09:27 13:03:40.00+01:00",
            "ExposureCompensation": "-2/3",
            "MaxApertureValue": 4,
            "SubjectDistance": "5.19 m",
            "MeteringMode": "Multi-segment",
            "FocalLength": "500.0 mm",
            "CustomRendered": "Normal",
            "ExposureMode": "Auto",
            "WhiteBalance": "Auto",
            "SceneCaptureType": "Standard",
            "FocalPlaneXResolution": 4438.35616438356,
            "FocalPlaneYResolution": 4445.96912521441,
            "FocalPlaneResolutionUnit": "inches",
            "ExifImageWidth": 3888,
            "ExifImageHeight": 2592,
            "ModifyDate": "2013:09:27 13:03:40.00+01:00",
            "CreateDate": "2013:09:27 13:03:40.00+01:00",
            "Rating": 0,
            "MetadataDate": "2013:09:27 13:03:40.00+01:00",
            "SerialNumber": 1130502837,
            "LensInfo": "500mm f/?",
            "Lens": "EF500mm f/4L IS USM",
            "LensID": 143,
            "ImageNumber": 0,
            "FlashCompensation": 0,
            "OwnerName": "Derek Lees WS66JU",
            "Firmware": "1.1.1",
            "Format": "image/tiff",
            "PreservedFileName": "IMG_8987.CR2",
            "SidecarForExtension": "CR2",
            "ColorMode": "RGB",
            "ISO": 400,
            "FlashFired": false,
            "FlashReturn": "No return detection",
            "FlashMode": "Off",
            "FlashFunction": false,
            "FlashRedEyeMode": false,
            "Creator": [
                "Derek Lees WS66JU",
                "Derek Lees"
            ],
            "Rights": "© Derek Lees 2013",
            "HistoryAction": "converted",
            "HistoryParameters": "from image/tiff to image/jpeg"
        },
        "APP14": {
            "DCTEncodeVersion": 100,
            "APP14Flags0": "[14], Encoded with Blend=1 downsampling",
            "APP14Flags1": "(none)",
            "ColorTransform": "YCbCr"
        },
        "Composite": {
            "Aperture": 8,
            "Flash": "Off, Did not fire",
            "ImageSize": "1000x658",
            "ScaleFactor35efl": 1.6,
            "ShutterSpeed": "1/1000",
            "CircleOfConfusion": "0.019 mm",
            "DOF": "0.03 m (5.18 - 5.20)",
            "FOV": "2.5 deg",
            "FocalLength35efl": "500.0 mm (35 mm equivalent: 809.4 mm)",
            "HyperfocalDistance": "1683.65 m",
            "LensID": "Canon EF 500mm f/4L IS",
            "LightValue": 14
        }
    }
]
user2600095
  • 103
  • 1
  • 1
  • 9
  • 1
    I'm assuming you've already tried [json_decode()](http://php.net/json_decode)? – echochamber Dec 10 '13 at 23:52
  • @echochamber Yes, I've tried that: $json = json_encode($exif, true); echo $json['FileSize']; – user2600095 Dec 10 '13 at 23:57
  • I'm getting *object property name separator ':' expected* from `json_last_error_msg()`. I think it's having trouble around `"Rights": "© Derek Lees 2013"` – Phil Dec 10 '13 at 23:58
  • I'd say you're having an issue with the `Rights` value encoding however it works fine over here - http://codepad.viper-7.com/3ZU7vY – Phil Dec 11 '13 at 00:08

1 Answers1

0

Since you mentioned PHP, the json_decode function in PHP will decode the JSON into a multi-level object (or array). From there you can use foreach or direct naming of the array/object section to get the data you want.

Joshua Walcher
  • 506
  • 4
  • 14