title: saving json data in hdfs in hadoop
body: <p>I have the following Reducer class</p>
  
  <pre><code>public static class TokenCounterReducer extends Reducer&lt;Text, Text, Text, Text&gt; {
      public void reduce(Text key, Iterable&lt;Text&gt; values, Context context)
              throws IOException, InterruptedException {
  
          JSONObject jsn = new JSONObject();
  
          for (Text value : values) {
              String[] vals = value.toString().split("\t");
              String[] targetNodes = vals[0].toString().split(",",-1);
              jsn.put("source",vals[1] );
              jsn.put("target",targetNodes);
  
          }
          // context.write(key, new Text(sum));
      }
  }
  </code></pre>
  
  <p>Going thru examples (disclaimer: newbie here),  I can see that the general output type seems to be like a key/value store.</p>
  
  <p>But what if I dont have any key in the output? or what if I want if my output is in some other format (json in my case)?</p>
  
  <p>Anyways, from the above code:
  I want to write <code>json</code> object to HDFS?</p>
  
  <p>It was very trivial in Hadoop streaming.. but how do i do it in Hadoop java?</p>