Im using https://github.com/meltingice/psd.js to parse a PSD file in node,
I see that toJSON() can be used, https://github.com/won21kr/psd.js-1
but when I try to use on a simple hello world after installing the module,
npm install psd
toJSON() gives me error:
info = psd.toJSON();
^ TypeError: Object # has no method 'toJSON'
normal log works fine,
var PSD = require('psd');
var psd = PSD.fromFile("AntoineVeglas_Filter_BW.psd");
psd.parse();
node = psd.tree().descendants()[0];
console.log(node);
info = psd.toJSON();
how to parse to valid json my psd tree object? cheers
You are aware that toJSON function is in a fork project of the original right? So if you install psd using npm, you will get the original project which has no toJSON function.
You should checkout the fork (won21kr) and either put it in your node_modules folder, or put it somewhere else and access the js file with a relative module path notation: require('./psd-fork/index.js').
change psd.tree().descendants()[0]; to psd.tree().descendants()[0].export();
Related
Got a problem reading an asset in Flutter web app. I've declared it in pubspec.yaml
But when I'm trying to load it with await rootBundle.loadString('test/sample_text.json'); I always get the same error Error while trying to load an asset: Failed to load asset at "assets/test/sample_text.json"
Never had such issue when developing for mobile
Assets in the web are placed under another assets/ directory, which results in the path being assets/assets/....
Create a simple function e.g. in lib/utils.dart:
import 'package:flutter/foundation.dart';
String path(str) {
return (kIsWeb) ? 'assets/$str' : str;
}
Wrap any path strings with this function, for example
AssetImage(path('assets/test/sample_text.json')).
the correct way to do this is packages/$your_package/assets/test/sample_text.json
I am working in Flutter and trying to open a json file in my assets folder. I found I can use the File() method, but it only seems to take an absolute path. Is there a way I can convert this to a relative path? I've tried using the relative path to the file already, but it returns an error saying no such file.
Here is the code so far. Basically I want to get the json file, and return it as a string (in the function readFileSync() below). Then I use that data to create a List object. If there's a better way to read a file into Flutter, I'm open to that too!
List<Answers> myFunction2() {
String arrayObjsText = readFileSync();
//print(arrayObjsText);
var tagObjsJson = jsonDecode(arrayObjsText)['tags'] as List;
var tagObjs =
tagObjsJson.map((tagJson) => Answers.fromJson(tagJson)).toList();
return tagObjs;
}
String readFileSync() {
String contents = new File(
'/Users/pstumbaugh/Documents/Computer Science/CS492 Mobile Dev/Dart-Flutter-CallMeMaybe/project3/assets/answers.json')
.readAsStringSync();
return contents;
}
I don't know much about how Futures work. I tried with those, but it seems like it always returns a Future and I'm not sure how to unpack that down to just a string without having to make everything async functions, which then led to problems when I try to get the List in my widgets on the main page...
You should to get assets not from relative path from your PC. When you install an app for a device or a emulator/simulator, it is can't access files on your computer. In few words, you can do it with loadString method from flutter/services.dart package (it is in Flutter SDK by default):
import 'package:flutter/services.dart' show rootBundle;
final data = rootBundle.loadString('assets/answers.json');
And make sure that you declared assets in pubspec.yaml config. Here is an official tutorial for how to work with assets.
I have exported a 3D model from Blender using the io_three addon.
Now I am trying to load this model into ThreeJS using code like this.
import React, { Component } from 'react';
import * as THREE from 'three';
var loader = new THREE.JSONLoader();
loader.load('./making_a_face10.json', handle_load);
I am consistently getting the same error message.
Unexpected token < in JSON at position 0
I have tried using the THREE.ObjectLoader() and also this option https://github.com/tweedegolf/parsed-model, but it keeps saying error in position 0 of JSON.
As a side note, I can access the JSON like this:
var JSONdata = require('./making_a_face10.json');
That does expose data inside the JSON, but I want the ThreeJS loader to work.
Then I found this example https://threejs.org/examples/#webgl_loader_json_blender and when I went to view the source code it shows that the 'model' is being imported as a .js file??, i.e. they are loading it like this:
loader.load( 'models/animated/monster/monster.js', function ( geometry, materials )...
There is ample material to explain what I want to do but none of it points to loading the model as a .js file.
two more notes - the format of my JSON file looks extremely like this https://github.com/mrdoob/three.js/blob/master/examples/models/animated/monster/monster.js and I am running a local server using npm start
If any whiz kid could help me out I would be extremely grateful.
SOLVED
In the React project folder. The .JSON file was in my /src folder. It should have been in my /public folder.
As Kryten mentioned in the comments.. Your load is failing. The first character in your JSON file is not a '<'. That looks like an XML response failure header.
The THREE loader uses XMLHTTPRequest internally... you could try loading your JSON directly with XMLHTTPRequest and then log the output to see what the error is..
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)
Has anyone tried to convert xml file into html webpage using XSLT stylesheet in node.js? My background is in Java. I normally use SAXON to convert XML into HTML webpages. I am a newbie to node.js. I have tried to implement this using few libraries like node_xslt, libxsltjs etc but was not successful. If anyone has tried using other libraries that works with XSLT stylesheet, please post a link. Any help would be appreciated.
If you want to use Saxon from a Node.js application, you basically have three choices, none of them ideal:
(a) call out to Java, using a variety of mechanisms.
(b) use the port of Saxon/C to Node.js being constructed here: https://github.com/rimmartin/saxon-node This is bleeding-edge stuff and I don't know how far the project has got.
(c) wait for Saxon-JS to arrive any time soon. See http://dev.saxonica.com/blog/mike/2016/02/introducing-saxon-js.html
At time of writing this works for me...
install saxon...
> npm install saxon-js (see https://www.npmjs.com/package/saxon-js)
write a little test program
const saxon = require('saxon-js');
const env = saxon.getPlatform(); const doc = env.parseXmlFromString(env.readFile("styles/listview.xsl"));
doc._saxonBaseUri = "dummy"; const sef = saxon.compile(doc);
let xml = "<EMPLOYEE_ID>107</EMPLOYEE_ID><FIRST_NAME>Summer</FIRST_NAME><LAST_NAME>Payne</LAST_NAME>summer.payne#example.com515.123.8181<HIRE_DATE>2016-06-07</HIRE_DATE><MANAGER_ID>106</MANAGER_ID><JOB_TITLE>Public Accountant</JOB_TITLE>";
let html = saxon.transform({
stylesheetInternal:sef,
sourceType: "xml",
sourceText:xml,
destination: "serialized"}, "async"
).then( output => {
console.log(output.principalResult);
} );
run the test program from the command line...
> node test.js
The output should be the transformed XML.
Luck.