So I'm trying to use this node package. The usage instructions state that I need to require a JSON file. Something like this :
var myschema = require('schema.json');
But when I run this it wants to find a node package by the name of 'schema.json' and throws an error "Cannot find module 'schema.json'". How do I avoid this error?
The name of the libray you linked to is json-schema-deref
As such, to import that library you would do:
var deRefLib = require('json-schema-deref')
Then to load your schema file you'd need to use a require with a relative path. If your schema is in the same directory as your JS file, you would use:
var mySchema = require('./schema.json')
Related
Lets say I've got the following json file (root of angular application):
{
"propertyName": "ABC"
}
I know that TypeScript cannot handle JSON imports directly so I delcared the following module according to TypeScript module documentation using wildcard (typings.d.ts):
declare module "*.json" {
const value: any;
export default value;
}
Now I am able to import a local json file (structure above) like this:
import * as config from './config.json';
After that I am able to use any property of the import like this:
let propertyA: string = (<any>config).propertyName;
Everything is fine, but when I try to use
let propertyA: string = config.propertyName;
I get the following error message:
ERROR in src/main.ts(9,26): error TS2339: Property 'propertyName'
does not exist on type 'typeof "*.json"'.
Any suggestions how to avoid this error during build process? The process finished successfully (including this error message) and I'm able to use the web application and also the needed property. It just generates an error message
I've had a similiar problem, since it's a json file, doesn't have a module and doesn't need to be compiled you can import it like it would be in javascript.
const config = require('./config.json');
There won't be any any error accessing the config attributes then and it still be working fine.
Remember you may need to import the #types/node package in order to use the require method.
I have a problem with jMeter and JSON Path Extractor.
I downloaded zip file for this plugin and copy content to ext file as it is written on the page. Then I also downloaded jmeter-plugins-manager-0.10.jar and copy it into ext folder.
Next step - downloaded a sample:
https://jmeter-plugins.org/img/examples/JSONPathExtractorExample.jmx
When i try to import it i'm getting exception:
missing
com.thoughtworks.xstream.mapper.conversionException:kg.apc.jmeter.samplers.DummySampler:kg.apc.jmeter.samplers.DummySampler
EDITED:
I love samples and documentation for libraries. There is no information about install additional jars... just download:
https://jmeter-plugins.org/?search=jpgc-dummy
And show must go on
Since JMeter 3.0 you don't need any plugin for JSON.
There is natively a new one :
http://jmeter.apache.org/usermanual/component_reference.html#JSON_Path_PostProcessor
Regarding the issue maybe you can report the problem to jmeter-plugins project
i used JSR223 Sampler where i parse input json and validate it's values in pure JavaScript. It seems more simple.
Here is and example code:
var json = JSON.parse(SampleResult.getResponseDataAsString());
//get your jmeter context
var ctx = org.apache.jmeter.threads.JMeterContextService.getContext()
var vars = ctx.getVariables();
if(json[0].itemId != 1){
AssertionResult.setFailureMessage(json);
AssertionResult.setFailure(true);
} else {
//and put data to this context, that you can use it in other components.
vars.put('validationJsonRequest', true);
}
To see added data just use Debug Sampler or Debug post processor (which you can investigate in View Result Tree)
Need one help with MRUnit. I am adding my config file to MapReduceDriver as below.
conf = mapReduceDriver.getConfiguration();
conf.addResource("path_to_config.xml");
When reducer class is trying to access the the property in setUp() mehtod, its not getting the values from the passed in configuration file.
Configuration conf = context.getConfiguration();
String appNameListStr = conf.get("CODE.MAPPING");
// this appNameListStr is returned as null;
Any suggestions/hints on this.
According to the javadocs passing in a String causes the classpath to be examined for a file with that name. You're trying to load a file from the local file system.
You should use addResource(URL url) or addResource(Path file) to look at the local file system.
For example:
conf.addResource(new File("path_to_config.xml").toURI().toURL());
I build a simple weka application using Weka 3.7.13 dev version using MAVEN. I have initialise the pom.xml function to get weka library from the repository.
i want to run a simple clustering algorithm using weka, and connecting it to MySQL database. As per documentation, the weka need to have a DatabaseUtil.props file which contains it's jdbc driver. I have setup that.
This is my project structure:
I can retrieve the DatabaseUtils.props using my code below. But somehow the weka itself cannot recognise the jdbc:Url and driver name which i already configure inside.
DatabaseUtil.props file:
# JDBC driver (comma-separated list)
jdbcDriver=com.mysql.jdbc.Driver
# database URL
jdbcURL=jdbc:mysql://127.0.0.1:3306/datamining
Java code which i trigger the Weka module:
public void dm(){
int cluster = 4;
InstanceQuery clusterQuery = null;
try{
//file reader of database utilities properties
ClassLoader classLoader = getClass().getClassLoader();
File fileProps = new File(classLoader.getResource("DatabaseUtils.props").getFile());
//setup the data preparation functionality then connect to database
clusterQuery = new InstanceQuery();
clusterQuery.setUsername("test");
clusterQuery.setPassword("test");
clusterQuery.setQuery("SELECT * FROM TEMP_KMEANS");
clusterQuery.setCustomPropsFile(fileProps);
But when executed the function returning error: java.sql.SQLException: No suitable driver found for jdbc:idb=experiments.prp
It seems that the DatabaseUtils.props file cannot override the default driver value jdbc:idb=experiments.prp
Any ideas why this is throwing?
Any feedback and answer much appreciated.
I created a DatabaseUtils.props file in the src / main / resources folder and wrote the following code. It worked for me, I'm using weka 3.8.0.
File file = new File(getClass().getClassLoader().getResource("DatabaseUtils.props").toURI());
InstanceQuery query = new InstanceQuery();
query.setCustomPropsFile(file);
query.setUsername(MYSQL_USER);
query.setPassword(MYSQL_PASSWORD);
query.setQuery("select * from Action");
instances = query.retrieveInstances();
System.out.println(instances.toString());
The documentation says "These may be changed by creating a java properties file called DatabaseUtils.props in user.home or the current directory". Your properties file does not match those requirements (a properties file in a jar is not on the filesystem). See also Chapter 14 of the Weka manual.
An alternative solution is to set the URL in code using setDatabaseURL. As long as the JDBC driver is on the classpath this should work.
In my windows store app using the Visual Studio 2012 designer I want to be able to load some model objects for the designer. I've done this plenty of times before where I supply a xaml file using the ms-appx:/// uri without error. However, for this project I need to be able to instantiate a class and have it convert raw xml of a different format into my model objects.
I'm using the following xaml to instantiate my class for the designer:
d:DataContext="{Binding Source={d:DesignInstance Type=model:Walkthroughs, IsDesignTimeCreatable=True}}"
In my Walkthroughs class had code that did this initially:
public Walkthroughs()
{
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
AppDataLoader.LoadWalkthroughs(this, XDocument.Load("ms-appx:///SampleData/walkthroughs.xml"));
}
I first ran into an issue where the XDocument.Load did not understand the ms-appx:/// uri so I modified my code to something very simplistic:
AppDataLoader.LoadWalkthroughs(this, XDocument.Load(#"C:\walkthroughs.xml"));
Now I get access to path '' is denied.
I've tried several directories as well to no avail. I'm even running Visual Studio as an Administrator. If I remove the prefix altogether I get the following error:
Could not find file 'C:\Users\{me}\AppData\Local\Microsoft\VisualStudio\11.0\Designer\ShadowCache\omxyijbu.m4y\yofsmg1x.avh\walkthroughs.xml'.
Has anyone been able to load files from the file system when the designer instantiates objects?
Thanks,
-jeff
XDocument.Load(string uri) seems to have problems with loading Project resources from ms-appx:/
Regarding your second approach: Direct access to "C:" is not permitted. Ther is only a handful of special folders that you can access. Check out my workaround for this (my xml file is within the Assets folder of my project:
var storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
storageFolder = await storageFolder.GetFolderAsync("Assets");
var xmlFile = await storageFolder.GetFileAsync("data.xml");
var stream = await xmlFile.OpenReadAsync();
var rdr = new StreamReader(stream.AsStream(), System.Text.Encoding.GetEncoding("ISO-8859-1")); //needed if you have "ä,ß..." in your xml file
var doc = XDocument.Load(rdr);