I have a JSON file that I'm trying to add a sparql string to but when I load it using axios it comes is as a string instead of JSON.
Anyone know of a formatter that I could use to make this work?
If I remove the query all other values returns as JSON
[
{
"id": "{{faker 'datatype.uuid'}}",
"created_at": "{{faker 'date.recent' 365}}",
"query": "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
+"SELECT DISTINCT ?sub ?pred ?obj WHERE {\n"
+"<https://www.genenames.org/data/gene-symbol-report/#!/hgnc_id/HGNC:11998> ?pred ?obj .\n"
+"BIND (<https://www.genenames.org/data/gene-symbol-report/#!/hgnc_id/HGNC:11998> as ?sub)\n"
+"}LIMIT 100"
}
]
Related
When ı print my json_dump
{"accountNumber": 4176312, "currencyCode": "USD", "ownerName": "selman", "accountType": "individual", "balance": 0.0}
But when ı return
return make_response(jsonify(json_dump), status_code)
I see this
Why this ///// is coming ? How can ı solve this ?
json_dump is, presumably, a string of JSON, (representing an object).
jsonify will convert that string to a JSON representation of that string which will cause any " in it to be escaped.
Send json_dump to the browser (where you want a JSON representation of an object).
Don't use jsonify on something that is already JSON (since a JSON representation of a JSON representation of an object isn't very useful).
With any kind of Template Driven Extraction (TDE) in MarkLogic, how can I convert the results I get from the tde:node-data-extract function into RDF/JSON format? The JSON format returned by this method is not compliant with RDF/JSON, so I can't use it directly to insert triples into another database. In this case, I don't want to insert the triples into the same database that I'm applying the template against, I just want to use the template to create triples from XML data.
Here's an example of the JSON output that I get from the tde:node-data-extract function:
{
"document/pt/document/39627370": [{
"triple": {
"subject": "http://www.example.com/document/id/39627370",
"predicate": "http://www.example.com/typeOf",
"object": {
"datatype": "http://www.w3.org/2001/XMLSchema#string",
"value": "http://www.example.com/document"
}
}
},
{
"triple": {
"subject": "http://www.example.com/publisher/Oxford_University_Press",
"predicate": "http://www.example.com/typeOf",
"object": {
"datatype": "http://www.w3.org/2001/XMLSchema#string",
"value": "http://www.example.com/publisher"
}
}
}
}
}
Convert each "triple" property into a triple object using sem.triple(). Then serialize the array of sem.triple objects using sem.rdfSerialize().
https://docs.marklogic.com/sem.triple
https://docs.marklogic.com/sem.rdfSerialize
With the help from John and Mads, I found a slight variation that works really well assuming you're in the query console. $docs is any sequence of documents and $template is the TDE template.
let $jsontriples := tde:node-data-extract($docs, $template)
for $key in map:keys($jsontriples)
let $entry := map:get($jsontriples, $key)
return $entry["triple"]
This will return the triples automatically serialized into Turtle format in the query console Result tab, which you can switch to JSON or Text. I assume the answer from John is the most correct in a situation where the serialization is not automatically performed (e.g. when not using the query console).
I am trying to extract a node from a json file for a json element that matches another node in same element.
To be more specific, I want the names of all students in the sample json below who has "certified":"false"
Example JSON
{
"Students": [
{
"name": "John",
"Rank": "1",
"certified":"false"
},
{
"name": "Ashley",
"Rank": "5",
"certified":"true"
}
]
}
Code i am using is (gives me empty output) :
Library JSONLibrary
JSON_Verification
[Documentation] Testing JSON load logic
${metadataJson_object}= Load JSON From File ../TestData/sample.json
Log ${metadataJson_object}
#{studentName}= Get Value From Json ${metadataJson_object} "$..[?(#.certified=='false')]#.name"
Log #{studentName}
Indeed you were very close to it, # notation is not needed after filter. Just change the json path to =
$.Students[?(#.certified=='false')].name
Here :
$ -> root element
. -> child operator or to access the property
?() -> filter expression and
# -> current node
${json}= Convert String to JSON ${Getjson}
${name}= Get Value From Json ${json} $.Students[?(#.certified=='false')].name
Output
I'm using JSON Path PostProcessor with path expressions to store a JSON object from a JSON response, but when I later retrieve the variable, it has been reduced to string with key - pair values. So I don't know that was a string or number.
Example:
Response looks like this
{
.
.
"currency" : {
"code" : "AUD",
"name" : "Australian Dollars",
"symbol" : "$"
},
.
}
Using the path expression, I find currency and save it.
However, when I use it in a HTTP Request body data ("currency" : ${currency},),
it comes like this:
"currency" : {code=AUD, name=Australian Dollars, symbol=$},
How do I get the JSON Path PostProcessor to save the JSON object 'as is" without losing the data type details? Should I be using a different approach instead of JSON Path?
I would recommend switching to JSR223 PostProcessor and Groovy language, this way you will have full control of what is going on and be able to do what you want.
Assuming you have the following JSON response:
{
"currency": {
"code": "AUD",
"name": "Australian Dollars",
"symbol": "$"
}
}
the relevant Groovy coode will be something like:
def json = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def currency = json.currency
def currencyString = new groovy.json.JsonBuilder(currency).toPrettyString()
vars.put('currency', currencyString)
log.info(currencyString)
Demo:
References:
Groovy - Learn
Groovy - Parsing and producing JSON
Groovy is the New Black
I'm trying to extract the parameter roomNo from the following JSON with JMETER XPATH Extractor:
*/
{
"categoryCode": ["I4"],
"Response": {
"class": "example",
"availables": {
"available": [
{
"Desc": " Middle",
"roomNo": "5049"
},
{
"Desc": " Middle",
"roomNo": "5062"
}
],
"class": "test"
},
"advisoryInfo": null
},
"storeId": "10251"
}
*/
i use the following expression with no success:
/Response/availables/available[0]/roomNo
is the expression wrong?
UPDATE:
i'm try to use the plugins JSON PATH EXTRATCTOR. i tryied the following queries with no success:
$...available[0]
$.Response.availables.available..roomNo[0]
$.Response.availables.available[0].roomNo
UPDATE1:
one more consideration: the ajax response I recieve starts with */, is it possible this creates troubles with JSON EXTRACTOR? i see the response through view Results Tree
UPDATE2:
i try the following approach:
ajax request followed by bash extractor, followed by json extractor but it is still not working
in bash extractor i did as suggested using the following strings
String temp = new String(prev.getResponseDataAsString());
prev.setResponseData(temp.replaceAll("\*/","").getBytes());
some more question:
is it possible to see the result of bash extractor?
should i declare before json extractor that it should use temp variable? how?
I'm afraid XPath Extractor won't let you parsing JSON.
You'll need JSONPath Extractor available via JMeter Plugins (you need Extras with Libs Set).
In your case relevant JSONPath query will look like:
$.Response.availables.available..roomNo[0]
Check out Using the XPath Extractor in JMeter guide (scroll down to Parsing JSON) for more information and XPath to JSONPath mappings table.
Hope this helps.
UPD. You can use Beanshell Post Processor to get rid of your */ bits, in that case JSONPath should work fine. Beanshell PostProcessor code:
String temp = new String(prev.getResponseDataAsString());
prev.setResponseData(temp.replaceAll("\\*/","").getBytes());
Make sure that Beanshell Post Processor goes before JSONPath Extractor.