title: Apache NiFi ConvertRecord Rename Fields While Converting from CSV to JSON
body: <p>I have the following sample data incoming in a CSV file:</p>
  
  <pre><code>Identifer Key,Name,Address,City,State,ZIP  
  WELD-424,Jane Doe,123 Main St,Whereverville,CA,90210  
  MOWN-175,John Doe,555 Broadway Ave,New York,NY,10010
  </code></pre>
  
  <p>The processor flow I came up with so far is:</p>
  
  <ol>
  <li><strong>GetFile</strong></li>
  <li><strong>UpdateAttribute</strong> to set the <code>avro.schema</code> property with the schema text</li>
  <li><strong>PutMongoRecord</strong> uses <code>CSVReader</code> to load the records into the database</li>
  </ol>
  
  <p>What would the Avro schema look like for this? Here is my best guess (based on the two fields I care about):</p>
  
  <pre><code>{
     "type" : "record",
     "namespace" : "TheNameSpace",
     "name" : "MySchema",
     "fields" : [
       { "name" : "Identifier Key" , "type" : ["string"]}
       { "name" : "Name" , "type" : ["string", "null"]}
     ]
  }
  </code></pre>
  
  <p>Specifying <code>"Identifier Key"</code> above gives an error because it contains a space. Other fields like <code>"Name"</code> load fine however.</p>
  
  <p><strong>Some challenges I am facing:</strong> </p>
  
  <ul>
  <li>How do you rename fields? Does that need to be done in another processor block outside of the <code>ConvertRecord</code> processor and schema ecosystem? This seems like a common scenario because you will want fields to have the same name coming from many different sources.</li>
  <li>Avro does not like field names with spaces in them ( so going from <code>"Identifier Key" -&gt; "_id"</code> is going to be problematic).</li>
  <li>There does not seem to be a way to rename a field during a read and write operation. I thought the aliases capability would help (for example: going from <code>"Name" -&gt; "fullName"</code>)</li>
  <li>Make a single field (i.e. Identifier Key) all lower case before importing to MongoDB?</li>
  </ul>
  
  <p>I also tried using the <code>ConvertRecord</code> processor block to convert from CSV to JSON first so that it can be imported into MongoDB as JSON. It would need to look something like this (with the identifier key field all lowercase) but the field comes out <code>null</code> for the <strong>Identifier Key</strong> after <code>ConvertRecord</code> runs:</p>
  
  <pre><code>{"_id": "weld-424", "fullName": "Jane Doe", "updated": {"$date":"2018-11-01T04:00:00.000Z"}, "created": {"$date":"2018-11-01T04:00:00.000Z"}}
  {"_id": "mown-175", "fullName": "John Doe", "updated": {"$date":"2018-11-01T04:00:00.000Z"}, "created": {"$date":"2018-11-01T04:00:00.000Z"}}
  </code></pre>