My JSON Block
{
"type": "abcd",
"data": {
"id": [
"efgh"
],
"model": "ijkl"
}
I tried updating 'type' using the following curl post, but it doesn't like it.
curl -X PUT -d '{"id":["ABCD"]}'
Related
Imitating: https://blog.vespa.ai/billion-scale-knn/
Command line:
curl -s -d '{"yql":"select * from user where {\"targetHits\":10}nearestNeighbor(approximate, q_binary_code);","ranking.features.query(q_binary_code)":[1,2,3,4,5,6,7,8,9,10],"hits":10}' -H "Content-Type: application/json" -X POST http://localhost:8080/search/ | jq .
Error message:
{
"root": {
"id": "toplevel",
"relevance": 1,
"fields": {
"totalCount": 0
},
"errors": [
{
"code": 4,
"summary": "Invalid query parameter",
"source": "content",
"message": "Expected a tensor value of 'query(q_binary_code)' but has [1,2,3,4,5,6,7,8,9,10]"
}
]
}
}
Question: How pass q_binary_code?
With recent Vespa versions, you can define the query tensor in the schema. It must be defined
schema code {
document code {
field id type int {..}
field binary_code type tensor<int8>(b[16]) {..}
}
rank-profile coarse-ranking {
inputs {
query(q_binary_code) tensor<int8>(b[16])
}
num-threads-per-search:12
first-phase { expression { closeness(field,binary_code) } }
}
You also must define the rank profile in the query request:
curl -s -d '{"yql":"select * from user where {\"targetHits\":10}nearestNeighbor(binary_code, q_binary_code);","ranking.features.query(q_binary_code)":[1,2,3,4,5,6,7,8,9,10],"hits":10, "ranking": "coarse-ranking"}' -H "Content-Type: application/json" -X POST http://localhost:8080/search/ | jq .
Say I have a sample.json file that looks like this. Notice the objects are not separated by a comma. I am aware that this is not a JSON file without the commas.
[
{
"type": "message",
"user": "U024HFHU5",
"text": "hey there",
"ts": "1385407681.000003"
}
{
"type": "message",
"user": "U024HGJ4E",
"text": "right back at you",
"ts": "1385407706.000006"
}
]
How do I make it look like this (example from I got the example from https://thoughtbot.com/blog/jq-is-sed-for-json.)
[
{
"type": "message",
"user": "U024HFHU5",
"text": "hey there",
"ts": "1385407681.000003"
},
{
"type": "message",
"user": "U024HGJ4E",
"text": "right back at you",
"ts": "1385407706.000006"
}
]
I tried doing },{ as some have suggested but it does not work.
I think it's probably something like this in jq on the command line but am not sure. Here, my hope is that sample2.json outputs the desired format.
jq -r '. | join(", ")' sample.json > sample2.json
If the square brackets were not in the input, jq could process it like normal as a stream of objects. You could then throw them into an array or whatever.
You'll just need to invoke jq twice in this case. First read it in raw (-Rs) and trim out the leading and trailing brackets, output it raw (-r), then process in jq like normal.
$ jq -Rsr 'gsub("^\\s*\\[|\\]\\s*$"; "")' input.json | jq -n '[inputs]'
Using human JSON utility to recover your malformed JSON file:
hjson -j file
[
{
"type": "message",
"user": "U024HFHU5",
"text": "hey there",
"ts": "1385407681.000003"
},
{
"type": "message",
"user": "U024HGJ4E",
"text": "right back at you",
"ts": "1385407706.000006"
}
]
The option -j outputs the file with correct JSON syntax, by adding the missing comma between objects.
This question already has answers here:
Unexpected ConvertTo-Json results? Answer: it has a default -Depth of 2
(2 answers)
Closed 3 years ago.
I have the following JSON
{
"method": "exec",
"params": [
{
"url": "/sys/login/user",
"data": [
{
"user": "MyUsername",
"passwd": "MyPassword"
}
]
}
],
"id": 1,
"ver": "2.0"
}
I'm trying to build this JSON using Powershell, but the output is not correct, below is my code.
$fullJson=#{}
$params=#()
$paramsdata=#()
$paramsdata+=#{"user"="mailapi"}
$paramsdata+=#{"passwd"="**********"}
$params+=#{"url"="/sys/login/user"}
$params+=#{"data"=$paramsdata}
$fullJson.Add("method", "exec")
$fullJson.Add("params",$params)
$fullJson.Add("id", "1")
$fullJson.Add("ver", "2.0")
$JsonBody=$fullJson | ConvertTo-Json
$x=Invoke-WebRequest -Uri https://10.10.10.10/jsonrpc -Body $JsonBody -Method Post
The output is the below
{
"method": "exec",
"params": [
{
"url": "/sys/login/user"
},
{
"data": "System.Collections.Hashtable System.Collections.Hashtable"
}
],
"id": "1",
"ver": "2.0"
}
The problem is DATA properties is not correct format, it should be an a nested array inside the first one, but it seems that its being added as a hashtable.
This problem is the data array should be built like this one below
"params": [
{
"url": "/sys/login/user",
"data": [
{
"user": "MyUsername",
"passwd": "MyPassword"
}
]
But with my code, its being built like this
"params": [
{
"url": "/sys/login/user"
},
{
"data": "System.Collections.Hashtable System.Collections.Hashtable"
}
],
Any help in updating this.
Thanks
Use the -Depth option in ConvertTo-Json :
Specifies how many levels of contained objects are included in the
JSON representation. The default value is 2.
Your desired depth is 4 (object -> params -> data -> username/password) :
$JsonBody=$fullJson | ConvertTo-Json -Depth 4
Say I have a data structure like this in cloudant where this is one record:
{
"UserId": "0014807347",
"Conq": {
"reqs": "Testing",
"tag": "ARRANGEMENT"
},
"Outcome": {
"tag": "ARRANGEMENT",
"rating": 0
},
"id": "cdc11dc55a0006bb544d235e7dc1540a"
}
How could I transform each record of a particular table to add new fields?
Do a PUT with the id and current revision with the updated JSON body:
curl https://$USERNAME:$PASSWORD#$USERNAME.cloudant.com/$DATABASE/cdc11dc55a0006bb544d235e7dc1540a\
-X PUT \
-H "Content-Type: application/json" \
-d "$JSON"
{
"_id": "cdc11dc55a0006bb544d235e7dc1540a",
"_rev": "1-THE_CURRENT_REV_ID_HERE",
"UserId": "0014807347",
"Conq": {
"reqs": "Testing",
"tag": "ARRANGEMENT"
},
"Outcome": {
"tag": "ARRANGEMENT",
"rating": 0
},
"my_new_data_field": "My New Content Goes Here"
}
}
You should get a response of the type:
{
"ok":true,
"id":"cdc11dc55a0006bb544d235e7dc1540a",
"rev":"2-9176459034"
}
The current revision (indicated by 1-THE_CURRENT_REV_ID_HERE above) should be the revision you got when the document was last written.
The example /annotateText Concept Insights call provides the following example output:
curl -H 'Content-Type: text/plain' -d 'IBM announces new Watson services.'
'https://watson-api-explorer.mybluemix.net/concept-insights/api/v2/graphs/wikipedia/en-20120601/annotate_text'
{
"annotations": [
{
"concept": {
"id": "/graphs/wikipedia/en-20120601/concepts/Watson_(computer)",
"label": "Watson (computer)"
},
"score": 0.99832845,
"text_index": [
18,
24
]
},
{
"concept": {
"id": "/graphs/wikipedia/en-20120601/concepts/IBM",
"label": "IBM"
},
"score": 0.9980473,
"text_index": [
0,
3
]
}
]
}
What is the meaning of the text_index parameter that is being returned?
text_index tells you the start and end position where the identified concept is.
In your example, the concept IBM_Watson was identified in the snippet IBM announces new Watson.