I'm using a JSON like this one
[
[{
"tool": "one",
"products": [
"Prod1",
"Prod2",
"Prod3",
"Prod4",
"Prod5",
"Prod6"
],
"count": 6
}],
[{
"tool": "two",
"products": [
"Prod1",
"Prod7",
"Prod3",
"Prod8",
"Prod5",
"Prod9"
],
"count": 6
}],
{
"tool": "three",
"products": [
"Prod10",
"Prod70",
"Prod30"
],
"count": 3
}
]
and I'd like to extract all the Prod* that are about the tool "one" so the list
"Prod1",
"Prod2",
"Prod3",
"Prod4",
"Prod5",
"Prod6"
and then the same about the tools "two" and "three".
I'm in troubles with the right filter to use to obtain the result.
Any suggestion will be appreciated and thank you in advance
$..[?(#.tool=="one")] should filter the node that you are interested. you can then access the products list using
$..[?(#.tool=="one")].products.*
Use https://jsonpathfinder.com/ to find the exact output path and then use https://jsonpath.com/ to try different jsonpath-expressions
Related
How do you remove a value from an object in an http patch request?
For example:
{
"types": [
{
"id": 12,
"name": "xyz",
},
{
"id": 13,
"name": "ABC",
}
]
}
How do you remove where type/id=13?
Is it like this?
[{
"op":"remove",
"path":"types/13"
}]
Or like this?
[{
"op":"remove",
"path":"types",
"value":[{"id":13}]
}]
Also, Im not looking the delete the position no2 solution!
Thanks :)
One solution I found by the 3rd party I was using was to "update" with "null" and that deletes the specific entry. (Im not sure if it works universally)
[{
"op":"replace",
"path":"types",
"value":[{
"id": 13,
"value": null
}]
}]
Yesterday I've asked about this question but got no response maybe because it was too specific related to Django REST Framework. I feel like it's simply the key-value pair problem in form-data I use to post. So I'm going to re-ask the question with simplified content.
What is the form-data format's equivalent for this raw JSON:
"markets": [
{
"market": 1,
"name": "White Stone",
"slabs": [
1,
2
],
"thicknesses": [
1,
2,
3
],
"finish_types": [
1
]
},
{
"market": 2,
"name": "White Marble",
"slabs": [
1
],
"thicknesses": [
1
],
"finish_types": [
1,
3,
6
]
}
]
I want to create a new Product instance with markets field. markets is an array and has its own attributes. Some of them are also arrays. I can't send more than 1 slabs, thicknesses, and finish_types each within a single markets. slabs, thicknesses, and finish_types are foreign keys.
When I tried to do the key-value pairs like the image above, the only saved elements are the last one inputed.
Here's the created markets:
"markets": [
{
"id": 65,
"market": 1,
"name": "White Stone",
"slabs": [
2
],
"thicknesses": [
3
],
"finish_types": [
1
]
}
]
And when I tried another key format like this no slabs and thicknesses will be saved:
"markets": [
{
"id": 66,
"market": 1,
"name": "White Stone",
"slabs": [],
"thicknesses": [],
"finish_types": [
1
]
}
]
According to this answer.
How about you try this format:
Key Value
markets[0][market] 1
markets[0][name] white stone
markets[0][slabs][] 2
markets[0][thicknesses][] 3
markets[0][finish_types][] 1
And maybe this Django thread might help you.
Is there a way to select only some countries of a json file?
For example, given this json that represents the NUTS 2 subdivisions of the various European countries, I would like to modify it and select only a few countries.
For example, if I wanted only Italy (and its regions) how could I do that?
I looked for sites on the Internet that did this but I didn't find anything, and processing the file manually seems a madness.
Thanks
I tried to edit the file manually but there are some problems.
The file structure is:
{
"type": "Topology",
"objects":
{
"nuts2":
{
"type": "GeometryCollection",
"bbox": [-63.15345500000001, -21.387309500000015, 55.83662850000002, 71.18531800099998],
"geometries": [
{
"type": "Polygon",
"properties":
{
"nuts_id": "ITC1",
"name": "Piemonte",
"population": 4374052
},
"id": "ITC1",
"arcs": [
[2243, 2244, 2245, -1918, -1908, 2246, -122, -164]
]
},
...
...
{
"type": "MultiPolygon",
"properties":
{
"nuts_id": "ITI4",
"name": "Lazio",
"population": 5557276
},
"id": "ITI4",
"arcs": [
[
[-2356, -2359, -2258, -2262, -2268, 2361, -2347],
[2362]
],
[
[2363]
],
[
[2364]
],
[
[2365]
],
[
[2366]
]
]
},
]
}
},
"arcs": [
[
... PROBLEM HERE
]
],
"transform":
{
"scale": [0.011900198369836986, 0.009258188568956896],
"translate": [-63.15345500000001, -21.387309500000015]
}
}
I removed the "geometries" elements that do not interest me, leaving only the Italian nuts 2.
The problem is the content inside "arcs": the elements are many and hardly recognizable..
The only thing you can do here is selecting them one by one, because the regions of Italy aren't inside a mother clause that enclouses all of them.
What you can also do if all the Italy regions are together in the Json file is iterate to the first one and exit the loop in the last region.
For example, in my data.json file:
[
{
"course": [
"science"
],
"units": "3"
},
{
"course": [
"math"
],
"units": "6"
}
]
I want to write an API that can perform the GET method. For example, I want to make an api url like this:
example.com/api/{science or math}
it will return another json file that have the corresponding data like this:
[
{
"course": [
"science"
],
"units": "3"
}
]
Is there a way to perform this and how?
Find out a git repository called json-server and that is what I need :)
I have a deeply nested document(pseudo structure as shown below):
[{
"id": "1",
"company_id": "1",
"company_name": "company_1",
"departments":[{
"dep1" : [{
"id" : 40,
"name" : xyz
},
{
"id" : 41,
"name" : xyr
}],
"dep2": [{
}]
}]
"employeePrograms" :[{
}]
}]
How can I index these type of documents in Apache Solr?
Documentation gives the idea of immediate child documents alone.
Unfortunatelly i'm don't have huge experience with this technology, but want to help. Here is some official documentation, that might be useful: oficial doc
more specific
If you have some uncommon issue, tell about it, maybe any error, or whatever.. I would try my best to help)
Upd1 :
Solr can only maintain a 'flat' representation of the data. What you weretrying to do is not really possible. There are a number of workarounds, such as using dynamic fields and using a solr join to link multiple data sets.
Speking about a deep nesting ? I've found such an example of work around.
If you had something like that:
"docs": [
{
"name": "Product Name",
"categories": [
{
"name": "Category 1",
"priority": 8
},
{
"name": "Category 2",
"priority": 6
}
...
]
},
You have to modify it like that to make it not deeply nested :
"docs": [
{
name: "Sample Product"
categories: [
{
priority_category: "9_Category 1",
},
{
priority_category: "5_Category 2",
}
...
]
},
So, you've done something similar, check if there are any errors anywhere