How can I solve FireBase database forbidden characters in Key or a workaround
<p>I have this FireBase database structure an really would love to have the key like this example:</p>

<pre><code>"US": {
    "name": "United States",
    "PATH_TO_STREETS": {
        "US/California/Orange County/Orange/3138 E Maple Ave": "-K1234567"
        "US/California/Orange County/Orange/3139 E Maple Ave": "-K12334rt"
        "US/California/Orange County/Orange/3140 E Maple Ave": "-K1234r34"
     },
 }
</code></pre>

<p>Because the key is unique it´s a really good idea if it wasn't for the Firebase forbidden database characters:</p>

<pre><code>. (period)    
$ (dollar sign)    
[ (left square bracket)    
] (right square bracket)    
 (hash or pound sign)    
/ (forward slash)    
</code></pre>

<p>The <code>California</code> path that the above key consist of comes from Google Places api, and I wonder if any more of the forbidden database characters can pop up, and how to counteract this from blowing up when a future key have a # or $.</p>

<p>I also need a way to work with this key like:</p>

<pre><code>String[] split = theKey.split("/");
</code></pre>

<p>If I replace the (forward slash) what should I use, or how can a do this in another way maybe. Does Google Places api´s autocomplete result have any of the forbidden database characters?  </p>

<p>I could do like:</p>

<pre><code>// test for . $ # [ ] / and replace them
public static String removeInvalidChars(String text) {
    text = text.replace(".", "");
    text = text.replace("$", "");
    text = text.replace("#", "");
    text = text.replace("[", "");
    text = text.replace("]", "");
    text = text.replace("/", "");
    return text;
}
</code></pre>

<p>With this <code>removeInvalidChars</code> it will blow up I think, feels like I loose control over the key structure:   </p>

<pre><code>"US/California/Orange County/Orange/3138 E Maple Ave"
</code></pre>

<p>Maybe should I create s separate root node where a hash version of the above path is stored. Then I save the Hashes like :</p>

<pre><code>"US": {
    "name": "United States",
    "HASH_TO_STREETS": {
        "sadsasasjkinIGhGVBJKHBHIUOuijHdBJLI": "US/California/Orange County/Orange/3138 E Maple Ave",
        "KJHGjgh67HGCFhgvhjbIuiokkBHJbkjhBkj": "US/California/Orange County/Orange/3139 E Maple Ave",
        "LKJHNJHKHky7y78gHGHGJ675JHJHdbHJBjh":  "US/California/Orange County/Orange/3139 E Maple Ave"
     },
 }
</code></pre>

<p>Hey maybe that´s the answer...mm what do you think?</p>