Convert JSON schema to RAML data type.

@param  {string} jsonData - JSON file content.
@param  {string} typeName - Name of RAML data type to hold converted data.
503370
function js2dt (jsonData, typeName) {
  const data = JSON.parse(jsonData)

  const raml = new RamlConverter(data, typeName).toRaml()

  return raml
}
960292
public Datatype createDatatype(String typeLocalName)
            throws DatatypeException {
        if ("ID".equals(typeLocalName)) {
            return new Id();
        } else if ("IDREF".equals(typeLocalName)) {
            return Idref.THE_INSTANCE;
        } else if ("IDREFS".equals(typeLocalName)) {
            return Idrefs.THE_INSTANCE;
        } else if ("pattern".equals(typeLocalName)) {
            return Pattern.THE_INSTANCE;
        } else if ("datetime".equals(typeLocalName)) {
            return Datetime.THE_INSTANCE;
        } else if ("datetime-local".equals(typeLocalName)) {
            return DatetimeLocal.THE_INSTANCE;
        } else if ("datetime-tz".equals(typeLocalName)) {
            return DatetimeTz.THE_INSTANCE;
        } else if ("date-or-time".equals(typeLocalName)) {
            return DateOrTime.THE_INSTANCE;
        } else if ("date".equals(typeLocalName)) {
            return Date.THE_INSTANCE;
        } else if ("month".equals(typeLocalName)) {
            return Month.THE_INSTANCE;
        } else if ("week".equals(typeLocalName)) {
            return Week.THE_INSTANCE;
        } else if ("time".equals(typeLocalName)) {
            return Time.THE_INSTANCE;
        } else if ("iri".equals(typeLocalName)) {
            return Iri.THE_INSTANCE;
        } else if ("iri-ref".equals(typeLocalName)) {
            return IriRef.THE_INSTANCE;
        } else if ("string".equals(typeLocalName)) {
            return AsciiCaseInsensitiveString.THE_INSTANCE;
        } else if ("language".equals(typeLocalName)) {
            return Language.THE_INSTANCE;
        } else if ("media-query".equals(typeLocalName)) {
            return MediaQuery.THE_INSTANCE;
        } else if ("mime-type".equals(typeLocalName)) {
            return MimeType.THE_INSTANCE;
        } else if ("browsing-context".equals(typeLocalName)) {
            return BrowsingContext.THE_INSTANCE;
        } else if ("browsing-context-or-keyword".equals(typeLocalName)) {
            return BrowsingContextOrKeyword.THE_INSTANCE;
        } else if ("hash-name".equals(typeLocalName)) {
            return HashName.THE_INSTANCE;
        } else if ("integer".equals(typeLocalName)) {
            return Int.THE_INSTANCE;
        } else if ("integer-non-negative".equals(typeLocalName)) {
            return IntNonNegative.THE_INSTANCE;
        } else if ("integer-positive".equals(typeLocalName)) {
            return IntPositive.THE_INSTANCE;
        } else if ("float".equals(typeLocalName)) {
            return FloatingPointExponent.THE_INSTANCE;
        } else if ("float-non-negative".equals(typeLocalName)) {
            return FloatingPointExponentNonNegative.THE_INSTANCE;
        } else if ("float-positive".equals(typeLocalName)) {
            return FloatingPointExponentPositive.THE_INSTANCE;
        } else if ("mime-type-list".equals(typeLocalName)) {
            return MimeTypeList.THE_INSTANCE;
        } else if ("circle".equals(typeLocalName)) {
            return Circle.THE_INSTANCE;
        } else if ("rectangle".equals(typeLocalName)) {
            return Rectangle.THE_INSTANCE;
        } else if ("polyline".equals(typeLocalName)) {
            return Polyline.THE_INSTANCE;
        } else if ("xml-name".equals(typeLocalName)) {
            return XmlName.THE_INSTANCE;
        } else if ("meta-charset".equals(typeLocalName)) {
            return MetaCharset.THE_INSTANCE;
        } else if ("microdata-property".equals(typeLocalName)) {
            return MicrodataProperty.THE_INSTANCE;
        } else if ("charset".equals(typeLocalName)) {
            return Charset.THE_INSTANCE;
        } else if ("refresh".equals(typeLocalName)) {
            return Refresh.THE_INSTANCE;
        } else if ("paren-start".equals(typeLocalName)) {
            return ParenthesisStart.THE_INSTANCE;
        } else if ("paren-end".equals(typeLocalName)) {
            return ParenthesisEnd.THE_INSTANCE;
        } else if ("email-address".equals(typeLocalName)) {
            return EmailAddress.THE_INSTANCE;
        } else if ("email-address-list".equals(typeLocalName)) {
            return EmailAddressList.THE_INSTANCE;
        } else if ("keylabellist".equals(typeLocalName)) {
            return KeyLabelList.THE_INSTANCE;
        } else if ("zero".equals(typeLocalName)) {
            return Zero.THE_INSTANCE;
        } else if ("cdo-cdc-pair".equals(typeLocalName)) {
            return CdoCdcPair.THE_INSTANCE;
        } else if ("script".equals(typeLocalName)) {
            return Script.THE_INSTANCE;
        } else if ("script-documentation".equals(typeLocalName)) {
            return ScriptDocumentation.THE_INSTANCE;
        } else if ("functionbody".equals(typeLocalName)) {
            return FunctionBody.THE_INSTANCE;
        } else if ("a-rel".equals(typeLocalName)) {
            return ARel.THE_INSTANCE;
        } else if ("link-rel".equals(typeLocalName)) {
            return LinkRel.THE_INSTANCE;
        } else if ("meta-name".equals(typeLocalName)) {
            return MetaName.THE_INSTANCE;
        } else if ("non-empty-string".equals(typeLocalName)) {
            return NonEmptyString.THE_INSTANCE;
        } else if ("string-without-line-breaks".equals(typeLocalName)) {
            return StringWithoutLineBreaks.THE_INSTANCE;
        } else if ("simple-color".equals(typeLocalName)) {
            return SimpleColor.THE_INSTANCE;
        } else if ("time-datetime".equals(typeLocalName)) {
            return TimeDatetime.THE_INSTANCE;
        } else if ("svg-pathdata".equals(typeLocalName)) {
            return new SvgPathData();
        }
        throw new DatatypeException("Unknown local name for datatype: " + typeLocalName);
    }
1065029
function (oData, sFileType) {
				// code extension and properties files do not need formation
				if ((sFileType === "js") || (sFileType === "properties")) {
					return oData;
				}
				// other files should be formatted to JSON
				try {
					oData = JSON.parse(oData);
					return JSON.stringify(oData, null, '\t');
				} catch (oError){
					var ErrorUtils = sap.ui.require("sap/ui/fl/support/apps/contentbrowser/utils/ErrorUtils");
					ErrorUtils.displayError("Error", oError.name, oError.message);
					return oData;
				}
			}
1346535
function jsonit(data, type, setType) {
    if ('string' !== typeof data) {
      throw new JsonItError('Invalid JsonIt type: ' + typeof data)
    }
    var result = {}
    if (data.length > 0) {
      try {
        var colonPos = data.indexOf(':')
        var commaPos = data.indexOf(',')
        if (colonPos < 0 || (commaPos >= 0 && commaPos < colonPos)) {
          if (setType) defaultType = setType
          type = type || defaultType
          data = type + ':' + data
        }
        result = jsonic(data)
      } catch(err) {
        throw new JsonItError(err.message)
      }
    }
    return result
  }
840069
function baseFormat(data, strict) {
  const isArray = Array.isArray(data);

  if (!isArray && (data === null || typeof data !== 'object')) {
    throw new TypeError('data must be an Object or Array');
  }

  const records = [];

  if (isArray) {
    for (let i = 0, len = data.length; i < len; ++i) {
      records[i] = objectToRecord(data[i], strict);
    }
  } else {
    records.push(objectToRecord(data, strict));
  }

  return records.join('\n');
}
437420
@Override
    public String getTypeDefinition(String typeName) throws AtlasException {
        final IDataType dataType = typeSystem.getDataType(IDataType.class, typeName);
        return TypesSerialization.toJson(typeSystem, dataType.getName());
    }
745142
private List<Object> convertType(DataType type, byte[] data)
   {
      List<Object> result = new ArrayList<Object>();
      int index = 0;

      while (index < data.length)
      {
         switch (type)
         {
            case STRING:
            {
               String value = MPPUtility.getUnicodeString(data, index);
               result.add(value);
               index += ((value.length() + 1) * 2);
               break;
            }

            case CURRENCY:
            {
               Double value = Double.valueOf(MPPUtility.getDouble(data, index) / 100);
               result.add(value);
               index += 8;
               break;
            }

            case NUMERIC:
            {
               Double value = Double.valueOf(MPPUtility.getDouble(data, index));
               result.add(value);
               index += 8;
               break;
            }

            case DATE:
            {
               Date value = MPPUtility.getTimestamp(data, index);
               result.add(value);
               index += 4;
               break;

            }

            case DURATION:
            {
               TimeUnit units = MPPUtility.getDurationTimeUnits(MPPUtility.getShort(data, index + 4), m_properties.getDefaultDurationUnits());
               Duration value = MPPUtility.getAdjustedDuration(m_properties, MPPUtility.getInt(data, index), units);
               result.add(value);
               index += 6;
               break;
            }

            case BOOLEAN:
            {
               Boolean value = Boolean.valueOf(MPPUtility.getShort(data, index) == 1);
               result.add(value);
               index += 2;
               break;
            }

            default:
            {
               index = data.length;
               break;
            }
         }
      }

      return result;
   }
275035
function jsonToMm(data) {
    startMap();
    traverseTree( data.map.node, startTag, endTag );
    endMap();
}
122817
function parseTypeName(entityTypeName) {
  if (!entityTypeName) {
    return null;
  }

  var typeParts = entityTypeName.split(":#");
  if (typeParts.length > 1) {
    return makeTypeHash(typeParts[0], typeParts[1]);
  }

  if (__stringStartsWith(entityTypeName, MetadataStore.ANONTYPE_PREFIX)) {
    var typeHash = makeTypeHash(entityTypeName);
    typeHash.isAnonymous = true
    return typeHash;
  }
  var entityTypeNameNoAssembly = entityTypeName.split(",")[0];
  var typeParts = entityTypeNameNoAssembly.split(".");
  if (typeParts.length > 1) {
    var shortName = typeParts[typeParts.length - 1];
    var namespaceParts = typeParts.slice(0, typeParts.length - 1);
    var ns = namespaceParts.join(".");
    return makeTypeHash(shortName, ns);
  } else {
    return makeTypeHash(entityTypeName);
  }
}
867732
@Given("^I convert jsonSchema '(.+?)' to json and save it in variable '(.+?)'")
    public void convertJSONSchemaToJSON(String jsonSchema, String envVar) throws Exception {
        String json = commonspec.parseJSONSchema(new JSONObject(jsonSchema)).toString();
        ThreadProperty.set(envVar, json);
    }
1198939
private static ParamType typeConverter(String typeName) {
        if (typeName == null || typeName.isEmpty()) {
            return null;
        }

        if ("Number".equals(typeName) || "Long".equalsIgnoreCase(typeName)
                || "Integer".equals(typeName) || "int".equals(typeName)) {
            return ParamType.NUMBER;
        }

        if ("Boolean".equalsIgnoreCase(typeName)) {
            return ParamType.BOOLEAN;
        }

        if ("String".equals(typeName)) {
            return ParamType.STRING;
        }

        if ("Date".equals(typeName)) {
            return ParamType.DATE;
        }

        if ("File".equals(typeName)) {
            return ParamType.FILE;
        }

        return null;
    }
1055656
function (data) {
    var str = '', start = true;
    var jsondata = '';
    for (var key in data) {
      if (typeof (jsondata = JSON.stringify(data[key])) === 'string') {
        str += (start? '': '&');
        str += encodeURIComponent(key) + '=' + encodeURIComponent(jsondata);
        if (start) { start = false; }
      }
    }
    return str;
  }
1059346
private JsonElement parseJsonObjectType(JsonSchema schema, JsonElement value)
      throws DataConversionException {
    JsonSchema valuesWithinDataType = schema.getValuesWithinDataType();
    if (schema.isType(MAP)) {
      if (Type.isPrimitive(valuesWithinDataType.getType())) {
        return value;
      }

      JsonObject map = new JsonObject();
      for (Entry<String, JsonElement> mapEntry : value.getAsJsonObject().entrySet()) {
        JsonElement mapValue = mapEntry.getValue();
        map.add(mapEntry.getKey(), parse(mapValue, valuesWithinDataType));
      }
      return map;
    } else if (schema.isType(RECORD)) {
      JsonSchema schemaArray = valuesWithinDataType.getValuesWithinDataType();
      return parse((JsonObject) value, schemaArray);
    } else {
      return JsonNull.INSTANCE;
    }
  }
561239
function js2dtCLI (jsonFile, ramlTypeName) {
  const jsonData = fs.readFileSync(jsonFile).toString()

  if (ramlTypeName != null) {
    const raml = js2dt.js2dt(jsonData, ramlTypeName)
    return `#%RAML 1.0 Library\n${yaml.safeDump({ types: raml }, { 'noRefs': true })}`
  } else {
    const typeName = 'this__should__be__the__only__type'
    const raml = js2dt.js2dt(jsonData, typeName)

    const keys = Object.keys(raml)
    if (keys.length !== 1 || !keys.includes(typeName)) {
      throw new Error(`There is more than one type (${JSON.stringify(keys)}), please specify a name for the raml library`)
    }

    return `#%RAML 1.0 DataType\n${yaml.safeDump(raml[typeName], { 'noRefs': true })}`
  }
}
573274
public String toJsonP(final String callback, final Object data) {
        synchronized (lock) {
            try {
                return callback + "(" + stringify((JsonNode) mapper.valueToTree(data)) + ");";
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
207997
def type(self):
        
        value = self._schema.get("type", "any")
        if not isinstance(value, (basestring, dict, list)):
            raise SchemaError(
                "type value {0!r} is not a simple type name, nested "
                "schema nor a list of those".format(value))
        if isinstance(value, list):
            type_list = value
            # Union types have to have at least two alternatives
            if len(type_list) < 2:
                raise SchemaError(
                    "union type {0!r} is too short".format(value))
        else:
            type_list = [value]
        seen = set()
        for js_type in type_list:
            if isinstance(js_type, dict):
                # no nested validation here
                pass
            elif isinstance(js_type, list):
                # no nested validation here
                pass
            else:
                if js_type in seen:
                    raise SchemaError(
                        ("type value {0!r} contains duplicate element"
                         " {1!r}").format(value, js_type))
                else:
                    seen.add(js_type)
                if js_type not in (
                    "string", "number", "integer", "boolean", "object",
                    "array", "null", "any"):
                    raise SchemaError(
                        "type value {0!r} is not a simple type "
                        "name".format(js_type))
        return value
571872
private function validateType(array $jsonData): self
    {
        // execute start(s)
        $this->executeStarts($this->getSerializer()::readRuleStartIndexes($this->getTypeRule()));

        if (array_key_exists(DI::KEYWORD_DATA, $jsonData) === true &&
            array_key_exists(DI::KEYWORD_TYPE, $data = $jsonData[DI::KEYWORD_DATA]) === true
        ) {
            // execute main validation block(s)
            $index = $this->getSerializer()::readRuleIndex($this->getTypeRule());
            $this->executeBlock($data[DI::KEYWORD_TYPE], $index);
        } else {
            $title   = $this->formatMessage(Messages::INVALID_VALUE);
            $details = $this->formatMessage(Messages::TYPE_MISSING);
            $status  = JsonApiResponse::HTTP_UNPROCESSABLE_ENTITY;
            $this->getJsonApiErrorCollection()->addDataTypeError($title, $details, (string)$status);
            $this->addErrorStatus($status);
        }

        // execute end(s)
        $this->executeEnds($this->getSerializer()::readRuleEndIndexes($this->getTypeRule()));

        if (count($this->getErrorAggregator()) > 0) {
            $title  = $this->formatMessage(Messages::INVALID_VALUE);
            $status = JsonApiResponse::HTTP_CONFLICT;
            foreach ($this->getErrorAggregator()->get() as $error) {
                $details = $this->getMessage($error);
                $this->getJsonApiErrorCollection()->addDataTypeError($title, $details, (string)$status);
            }
            $this->addErrorStatus($status);
            $this->getErrorAggregator()->clear();
        }

        return $this;
    }