VB.NET json select name - json

I have a problem selecting a name.
I want to get icons/icon_16x16.png from objects. I already have done just that name.
My json:
{
"objects": {
"icons/icon_16x16.png": {
"hash": "bdf48ef6b5d0d23bbb02e17d04865216179f510a",
"size": 3665
}
}
}

Related

I want to call the same key in all arrays from a JSON that I'm pulling from an API. Something like API_Source["data"][1..4]. How can I do this?

Here is my current code where I'm using the API to seed a database.
#games.each do |game|
Game.create(
local_team: #games["data"][0]["visitorTeam"]["data"]["name"],
away_team: #games["data"][0]["localTeam"]["data"]["name"]);
end
I can go through, one by one, and just increase the "[0]" one line at a time, but that would make for a wall of syntax.
How can I call something like "[0, 1, 2, 3, 4]", etc?
Here's what #games looks like in JSON
{
"data": [
{
"localTeam": {
"data": {
"name": "Celtic",
}
},
"visitorTeam": {
"data": {
"name": "Rangers",
}
}
},
{
"localTeam": {
"data": {
"name": "Rangers",
}
},
"visitorTeam": {
"data": {
"name": "Hearts",
}
}
},
This continues for another 10 matches. I want to call around a few hundred so you can imagine why I'd want to streamline this.

How to feed a value into a field in a json array in Gatling?

I am using Gatling to test an API that accepts a json body like below:
{
"data": {
"fields": [
{
"rank": 1
},
{
"name": "Jack"
}
]
}
}
I have created a file feeder.json that contains array of json objects like above.
Below is the feeder.json
[
{
"data": {
"fields": [
{
"rank": 1
},
{
"name": "Jack"
}
]
}
}
]
I have created another file template.txt that contains the template of above json.
Below is the template.txt
{
"data": {
"fields": [
{
"rank": ${data.fields[0].rank} //this is not working
},
{
"name": "Jack"
}
]
}
}
val jsonFeeder = jsonFile("feeder.json").circular
scenario("Test scenario")
.feed(jsonFeeder)
.exec(http("API call test")
.post("/data")
.body(ElFileBody("template.txt"))
.asJson
.check(status is 200))
I am feeding the feeder.json and also sending json body from template.json. The 'rank' property values should get set from feeder into the json body. But I am getting an error 'Map named 'data' does not contain key 'fields[0]'. Stuck with this.
Access by index syntax uses parens, not square braces.
#{data.fields(0).rank}

How to set first order keys which are unique names in mongodb as id, during import of json file

[{
"lk":{
"car":"red",
"house":"green"
},
"nm":{
"car":"yellow",
"house":"blue"
},
"rn":{
"car":"cyan",
"house":"brown"
}
}]
Above is the data in json file, I want to import this data to mongodb with first order unique keys
i.e, "lk", "nm", "rn" as the id.
So My expected import is
{"_id":"lk",
"car":"red",
"house":"green"
}
Now my data after import from is like this
{
"_id": {
"$oid": "60a8bf4e5afb48c03a063bab"
},
"SJ_Center_1922": {
"20-4-2021": {
"lobby": {
"-Ma706vbb9ZZriiRFW6Y": "12:24:26"
},
"hall": {
"-Ma7096KOM6mn1ellHAt": "12:24:35",
"-Ma70KBxiuVJfwv-1YGH": "12:25:20"
}
},
"21-4-2021": {
"lobby": {
"-MaBacB5VBAjAyNynJci": "9:46:46",
"-MaC9obPzyUfnUNxWyJz": "12:24:55",
"-MaCAH_cs0Af2nDF_Gtg": "12:26:57"
},
"hall": {
"-MaBaccDC_7RBacIlVOk": "9:46:48",
"-MaBhwZtVqMgX4-p8ZxL": "10:18:45",
"-MaC8ZGiCKHxGv_-kLUQ": "12:19:25",
"-MaC9pNHMfxDpMMgtvgo": "12:24:58",
"-MaCAI1DyEo87XhOIaq_": "12:26:59"
}
}
}
}
I want to make "SJ_Center_1922" as id because that part is unique in all entries, so that I can query to extract data easily
Or If there is a better way to make sense of such data, please suggest

convert a JSON to another w/ circe

I would like to convert this JSON
{
"l1k1": {
"l2k1": "l2v1",
"l2k2": 1
},
"l1k2": [
{
"e1l1": "e1v1",
"e1l2": "e1v2"
},
{
"e2l1": "e2v1",
"e2l2": "e2v2"
}
]
}
to this one
{
"papa": {
"l1k1c": {
"l2k1c": {
"string": "l2v1"
},
"l2k2c": {
"int": 1
}
},
"l1k2c": {
"array": [
{
"e1l1": "e1v1",
"e1l2": "e1v2"
},
{
"e2l1": "e2v1",
"e2l2": "e2v2"
}
]
}
}
}
where:
"l" stands for level
"k" for key, "v" for value
"e" for element
"c" for copy (where "*" maps to "*c")
I'm using circe's Json but having a hard time renaming the keys or creating parents or children with it. As I'm writing this, I'm thinking I may need to use its ACursor instead. As you may have guessed, I'm trying to generate an AVRO doc from an input JSON. I'm open to help w/ my approach or any suggestions about how to go about it in a cleaner way.

How to check in elasticsearch if a JSON object has a key using the DSL?

If I have two documents within an index of the following format, I just want to weed out the ones which have an empty JSON instead of my expected key.
A
{
"search": {
"gold": [1,2,3,4]
}
B
{
"search":{}
}
I should just get A json and not B json.
I've tried the exists query to search for "gold" but it just checks for non null values and returns the list.
Note: The following doesn't do what I want.
GET test/_search
{
"query": {
"bool": {
"must": [
{
"exists": { "field": "search.gold" }}
]
}
}
}
This is a simple question but I'm unable to find a way to do it even after searching through their docs.
If someone can help me do this it would be really great.
The simplified mapping of the index is :
"test": {
"mappings": {
"carts": {
"dynamic": "true",
"_all": {
"enabled": false
},
"properties": {
"line_items": {
"properties": {
"line_items_dyn_arr": {
"type": "nested",
"properties": {
"dynamic_key": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
Are you storing complete json in search field?
If this is not the case then please share the mapping of your index and sample data.
Update: Query for nested field:
{
"query": {
"nested": {
"path": "search",
"query": {
"bool": {
"must": [
{
"exists": {
"field": "search.gold"
}
}
]
}
}
}
}
}
For nested type fields we need to specify the path and query to be executed on nested fields since nested fields are indexed as child documents.
Elastic documentation: Nested Query
UPDATE based on the mapping added in question asked:
{
"query": {
"nested": {
"path": "line_items.line_items_dyn_arr",
"query": {
"exists": {
"field": "line_items.line_items_dyn_arr"
}
}
}
}
}
Notice that we used "path": "line_items.line_items_dyn_arr". The reason we require to provide full path is because nested field line_items_dyn_arr is itself under line_items object. Had line_items_dyn_arr be a property of mapping and not the property of object or nested field the previous query would work fine.
Nishant's answer is right but for some reason I could get it working only if the path and field are the whole paths.
The following works for me.
{
"nested": {
"path": "search.gold",
"query": {
"exists": {
"field": "search.gold"
}
}
}
}