Adds the units and the dimensions reading a json file. It adds only dimensions and units that are not inside the db
        It is possible adding new dimensions and units to the DB just modifiyin the json file
516028
def create_default_units_and_dimensions():
    
    default_units_file_location = os.path.realpath(\
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     '../',
                     'static',
                     'default_units_and_dimensions.json'))

    d=None

    with open(default_units_file_location) as json_data:
        d = json.load(json_data)
        json_data.close()

    for json_dimension in d["dimension"]:
        new_dimension = None
        dimension_name = get_utf8_encoded_string(json_dimension["name"])

        db_dimensions_by_name = db.DBSession.query(Dimension).filter(Dimension.name==dimension_name).all()

        if len(db_dimensions_by_name) == 0:
            # Adding the dimension
            log.debug("Adding Dimension `{}`".format(dimension_name))
            new_dimension = Dimension()
            if "id" in json_dimension:
                # If ID is specified
                new_dimension.id = json_dimension["id"]

            new_dimension.name = dimension_name

            db.DBSession.add(new_dimension)
            db.DBSession.flush()

        # Get the dimension by name
        new_dimension = get_dimension_from_db_by_name(dimension_name)

        for json_unit in json_dimension["unit"]:
            db_units_by_name = db.DBSession.query(Unit).filter(Unit.abbreviation==get_utf8_encoded_string(json_unit['abbr'])).all()
            if len(db_units_by_name) == 0:
                # Adding the unit
                log.debug("Adding Unit %s in %s",json_unit['abbr'], json_dimension["name"])
                new_unit = Unit()
                if "id" in json_unit:
                    new_unit.id = json_unit["id"]
                new_unit.dimension_id   = new_dimension.id
                new_unit.name           = get_utf8_encoded_string(json_unit['name'])
                new_unit.abbreviation   = get_utf8_encoded_string(json_unit['abbr'])
                new_unit.lf             = get_utf8_encoded_string(json_unit['lf'])
                new_unit.cf             = get_utf8_encoded_string(json_unit['cf'])
                if "description" in json_unit:
                    # If Description is specified
                    new_unit.description = get_utf8_encoded_string(json_unit["description"])

                # Save on DB
                db.DBSession.add(new_unit)
                db.DBSession.flush()
            else:
                #log.critical("UNIT {}.{} EXISTANT".format(dimension_name,json_unit['abbr']))
                pass
    try:
        # Needed for test. on HWI it fails so we need to catch the exception and pass by
        db.DBSession.commit()
    except Exception as e:
        # Needed for HWI
        pass
    return
1264008
def bulk_add_units(unit_list, **kwargs):
    
    # for unit in unit_list:
    #     add_unit(unit, **kwargs)

    added_units = []
    for unit in unit_list:
        added_units.append(add_unit(unit, **kwargs))

    return JSONObject({"units": added_units})
1011589
public static Dimension readDimension(final DataInput pStream) throws IOException {
        int h = pStream.readShort();
        int v = pStream.readShort();
        return new Dimension(h, v);
    }
1011660
private function LoadClassesFromJson()
    {
        $classes_def = Json::Decode(
            file_get_contents(
                $this->definitions_path . "classes.json"
            )
        );
        
        $enumerations_def = array();
        
        if(file_exists($this->definitions_path . "class_enumerations.json"))
        {
            $enumerations_def = Json::Decode(
                file_get_contents(
                    $this->definitions_path . "class_enumerations.json"
                )
            );
        }
        
        $variables_def = array();
        
        if(file_exists($this->definitions_path . "class_variables.json"))
        {
            $variables_def = Json::Decode(
                file_get_contents(
                    $this->definitions_path . "class_variables.json"
                )
            );
        }

        foreach($classes_def as $header => $namespaces)
        {
            $this->symbols->AddHeader($header);
            
            foreach($namespaces as $namespace => $classes)
            {
                foreach($classes as $class_name => $methods)
                {   
                    $class = new Element\ClassElement(
                        $class_name
                    );
                    
                    // Set class details
                    if(isset($methods["_description"]))
                    {
                        $class->description = $methods["_description"];
                        unset($methods["_description"]);
                    }
                    
                    if(isset($methods["_parents"]))
                    {
                        $class->AddParents($methods["_parents"]);
                        unset($methods["_parents"]);
                    }
                    
                    if(isset($methods["_struct"]))
                    {
                        $class->struct = true;
                        unset($methods["_struct"]);
                    }
                    
                    if(isset($methods["_forward_declaration"]))
                    {
                        $class->forward_declaration = true;
                        unset($methods["_forward_declaration"]);
                    }
                    
                    if(isset($methods["_platforms"]))
                    {
                        $class->platforms = $methods["_platforms"];
                        unset($methods["_platforms"]);
                    }
                    
                    // Add methods
                    foreach($methods as $method_name => $method_overloads)
                    {
                        $method = new Element\FunctionElement($method_name);
                        
                        foreach($method_overloads as $method_overload)
                        {
                            $overload = new Element\Overload(
                                $method_overload["description"]
                            );

                            $overload->SetReturnType(
                                new Element\ReturnType(
                                    $method_overload["return_type"]
                                )
                            );
                            
                            if(isset($method_overload["constant"]))
                                $overload->constant = $method_overload["constant"];

                            if(isset($method_overload["static"]))
                                $overload->static = $method_overload["static"];

                            if(isset($method_overload["virtual"]))
                                $overload->virtual = $method_overload["virtual"];

                            if(isset($method_overload["pure_virtual"]))
                                $overload->pure_virtual = $method_overload["pure_virtual"];

                            if(isset($method_overload["protected"]))
                                $overload->protected = $method_overload["protected"];

                            if(isset($method_overload["parameters"]))
                            {
                                foreach($method_overload["parameters"] as $parameter)
                                {
                                    if(!isset($parameter["value"]))
                                        $parameter["value"] = "";
                                    
                                    if(!isset($parameter["description"]))
                                        $parameter["description"] = "";

                                    $param = new Element\Parameter(
                                        $parameter["name"], 
                                        $parameter["type"], 
                                        $parameter["value"],
                                        $parameter["description"]
                                    );

                                    if(isset($parameter["is_array"]))
                                    {
                                        $param->is_array = true;
                                    }

                                    $overload->AddParameter($param);
                                }
                            }

                            $method->AddOverload($overload);
                        }
                        
                        $class->AddMethod($method);
                    }
                    
                    // Add enumerations
                    if(isset($enumerations_def[$header][$namespace][$class_name]))
                    {
                        foreach($enumerations_def[$header][$namespace][$class_name] as $enumeration_name=>$enumeration_data)
                        {
                            if(!isset($enumeration_data["description"]))
                                $enumeration_data["description"] = "";
                            
                            $class->AddEnumeration(
                                new Element\Enumeration(
                                    $enumeration_name,
                                    $enumeration_data["options"],
                                    $enumeration_data["description"]
                                )
                            );
                        }
                    }
                    
                    // Add variables
                    if(isset($variables_def[$header][$namespace][$class_name]))
                    {
                        foreach($variables_def[$header][$namespace][$class_name] as $variable_name=>$variable_options)
                        {
                            $variable = new Element\ClassVariable(
                                $variable_name, 
                                $variable_options["type"]
                            );
                            
                            if(isset($variable_options["static"]))
                                $variable->static = $variable_options["static"];

                            if(isset($variable_options["mutable"]))
                                $variable->mutable = $variable_options["mutable"];

                            if(isset($variable_options["protected"]))
                                $variable->protected = $variable_options["protected"];

                            if(isset($variable_options["public"]))
                                $variable->public = $variable_options["public"];
                            
                            if(isset($variable_options["description"]))
                                $variable->description = $variable_options["description"];
                            
                            $class->AddVariable($variable);
                        }
                    }
                    
                    $this->symbols->headers[$header]->AddClass(
                        $class,
                        $namespace
                    );
                }
            }
        }

        unset($classes_def);
        unset($enumerations_def);
        unset($variables_def);
    }
511409
def read_json(filepath, intkeys=True, intvalues=True):
    
    d = json.load(ensure_open(find_filepath(filepath), mode='rt'))
    d = update_dict_types(d, update_keys=intkeys, update_values=intvalues)
    return d
154823
def load_json(file, new_root_dir=None, decompression=False):
    """"""
    if decompression:
        with open(file, 'rb') as f:
            my_object = load(f, decompression=decompression)
    else:
        with open(file, 'r') as f:
            my_object = load(f, decompression=decompression)
    if new_root_dir:
        my_object.root_dir = new_root_dir

    return my_object
955977
def add_data_dict(self, datadict):
        '''
        '''

        self.set_codes(list(datadict.keys()))
        self.add_data(list(datadict.values()))
386739
def load(source, **kwargs) -> JsonObj:
    
    if isinstance(source, str):
        if '://' in source:
            req = Request(source)
            req.add_header("Accept", "application/json, text/json;q=0.9")
            with urlopen(req) as response:
                jsons = response.read()
        else:
            with open(source) as f:
                jsons = f.read()
    elif hasattr(source, "read"):
        jsons = source.read()
    else:
        raise TypeError("Unexpected type {} for source {}".format(type(source), source))

    return loads(jsons, **kwargs)
1306095
def loadJSON(self, jdata):
        
        super(StringColumn, self).loadJSON(jdata)

        # load additional info
        self.__maxLength = jdata.get('maxLength') or self.__maxLength
711567
def load_json
      json_config_file = Utils.lookup_file @filenames[:json]

      config = Utils.load_json json_config_file
      config.empty? ? @default_config : @default_config.merge(config)
    end
985414
def _read_json_db(self):
        
        try:
            metadata_str = self.db_io.read_metadata_from_uri(
                self.layer_uri, 'json')
        except HashNotFoundError:
            return {}
        try:
            metadata = json.loads(metadata_str)
            return metadata
        except ValueError:
            message = tr('the file DB entry for %s does not appear to be '
                         'valid JSON')
            message %= self.layer_uri
            raise MetadataReadError(message)
1194031
@Override
  public JsonArray deepCopy() {
    if (!elements.isEmpty()) {
      JsonArray result = new JsonArray(elements.size());
      for (JsonElement element : elements) {
        result.add(element.deepCopy());
      }
      return result;
    }
    return new JsonArray();
  }
657156
private static JsonObjectBuilder addProperties( JsonObjectBuilder builder, VarValueDef value)
    {
    JsonArrayBuilder properties = Json.createArrayBuilder();
    value.getProperties().forEach( property -> properties.add( property));
    JsonArray json = properties.build();

    if( !json.isEmpty())
      {
      builder.add( PROPERTIES_KEY, json);
      }

    return builder;
    }
1304235
public void addJMDict(File file) throws IOException, SAXException {
		new JMDictParser().parse(file,
				new DictionaryJMDictReader(trie, errors),
				threeLetterlanguageCode);
	}
783425
def bulk_add_dimensions(dimension_list, **kwargs):
    
    added_dimensions = []
    for dimension in dimension_list:
        added_dimensions.append(add_dimension(dimension, **kwargs))

    return JSONObject({"dimensions": added_dimensions})
242921
def add_attributes(attrs,**kwargs):
    

    #Check to see if any of the attributs being added are already there.
    #If they are there already, don't add a new one. If an attribute
    #with the same name is there already but with a different dimension,
    #add a new attribute.

    # All existing attributes
    all_attrs = db.DBSession.query(Attr).all()
    attr_dict = {}
    for attr in all_attrs:
        attr_dict[(attr.name.lower(), attr.dimension_id)] = JSONObject(attr)

    attrs_to_add = []
    existing_attrs = []
    for potential_new_attr in attrs:
        if potential_new_attr is not None:
            # If the attrinute is None we cannot manage it
            log.debug("Adding attribute: %s", potential_new_attr)

            if attr_dict.get((potential_new_attr.name.lower(), potential_new_attr.dimension_id)) is None:
                attrs_to_add.append(JSONObject(potential_new_attr))
            else:
                existing_attrs.append(attr_dict.get((potential_new_attr.name.lower(), potential_new_attr.dimension_id)))

    new_attrs = []
    for attr in attrs_to_add:
        attr_i = Attr()
        attr_i.name = attr.name
        attr_i.dimension_id = attr.dimension_id
        attr_i.description = attr.description
        db.DBSession.add(attr_i)
        new_attrs.append(attr_i)

    db.DBSession.flush()
    

    new_attrs = new_attrs + existing_attrs

    return [JSONObject(a) for a in new_attrs]
562949
def _add_json_binary_field(b, serialized, field):
    '''' 
    '''
    try:
        val = b.decode('utf-8')
        serialized[field] = val
    except UnicodeDecodeError:
        val = base64.b64encode(b).decode('utf-8')
        serialized[field + '64'] = val