class GlobalizeJsResource extends JsonResource {

    @Override
    public LanguageBundle parse(InputStream inStream, FilterOptions options)
            throws IOException, ResourceFilterException {
        LanguageBundleBuilder bb = new LanguageBundleBuilder(false);    // TODO: can we use auto sequence# mode?
        try (InputStreamReader reader = new InputStreamReader(new BomInputStream(inStream), StandardCharsets.UTF_8)) {
            JsonElement root = new JsonParser().parse(reader);
            if (!root.isJsonObject()) {
                throw new IllegalResourceFormatException("The root JSON element is not a JSON object.");
            }
            JsonObject root_obj = root.getAsJsonObject();
            Set<Map.Entry<String, JsonElement>> root_elements = root_obj.entrySet();
            if (root_elements.size() != 1) {
                throw new IllegalResourceFormatException(
                        "Only one top level language tag element is allowed per file.");
            }
            Map.Entry<String, JsonElement> top_level = root_elements.iterator().next();
            String language = top_level.getKey();
            // We just hang on to the language tag as part of the bundle.
            // When doing an import, we can validate that the language tag matches what they
            // say they are importing.
            bb.embeddedLanguageCode(language);
            JsonElement language_obj = top_level.getValue();
            if (!language_obj.isJsonObject()) {
                throw new IllegalResourceFormatException("The top level language element is not a JSON object.");
            }
            addBundleStrings(language_obj.getAsJsonObject(), "", bb, 0);
        } catch (JsonParseException e) {
            throw new IllegalResourceFormatException("Failed to parse the specified JSON contents.", e);
        }
        return bb.build();
    }

}