JSONInputFormat is used to read JSON file formats, such as the example shown below:
{
"title": "Talk On Travel Pool",
"link": "http://www.flickr.com/groups/talkontravel/pool/",
"description": "Travel and vacation photos from around the world.",
"modified": "2009-02-02T11:10:27Z",
"generator": "http://www.flickr.com/",
"items": [
{
"title": "View from the hotel",
"link": "http://www.flickr.com/photos/33112458@N08/3081564649/in/pool-998875@N22",
"media": {"m":"http://farm4.static.flickr.com/3037/3081564649_4a6569750c_m.jpg"},
"date_taken": "2008-12-04T04:43:03-08:00",
"description": " Talk On Travel has added a photo to the pool: ",
"published": "2008-12-04T12:43:03Z",
"author": "nobody@flickr.com (Talk On Travel)",
"author_id": "33112458@N08",
"tags": "spain dolphins tenerife canaries lagomera aqualand playadelasamericas junglepark losgigantos loscristines talkontravel"
}
]
}
Configuration
Configuration names consist of the following parameters:
- hgrid247.json.member
Indicates which JSON member (object or field) should be extracted.
For example, to retrieve all objects containing the field published, set:
- Configuration name: hgrid247.json.member
- Configuration value: published
- hgrid247.json.fields
Indicates which field values should be extracted from the selected JSON member.
- When specifying multiple fields, separate them using a colon (:).
- hgrid247.json.fieldsparator
Indicates the separator used between extracted field values.
- Default value: semicolon (;)
- hgrid247.record.splitable
Indicates whether the input JSON file is splittable.
- Possible values: yes or no
- Default value: no
- hgrid247.split.size
Indicates the split size (in bytes) when the input is splittable.
-
Default value: HDFS block size
Behavior
- Parses JSON input files
- Selects JSON objects based on the configured member
- Extracts specified fields from matching objects
- Outputs field values as a single record using the configured field separator
- Supports optional file splitting for large JSON inputs
Example
Using the JSON example above:
When:
- hgrid247.json.member = published
The reader will extract all JSON objects that contain the
published field and output the configured field values accordingly.
{
"title": "View from the hotel",
"link": "http://www.flickr.com/photos/33112458@N08/3081564649/in/pool-998875@N22",
"media": {"m":"http://farm4.static.flickr.com/3037/3081564649_4a6569750c_m.jpg"},
"date_taken": "2008-12-04T04:43:03-08:00",
"description": " Talk On Travel has added a photo to the pool: ",
"published": "2008-12-04T12:43:03Z",
"author": "nobody@flickr.com (Talk On Travel)",
"author_id": "33112458@N08",
"tags": "spain dolphins tenerife canaries lagomera aqualand playadelasamericas junglepark losgigantos loscristines talkontravel"
}
When the configuration is set as shown in the figure above, the output will be:
View from the hotel ;nobody@flickr.com (Talk On Travel)