I'm trying to insert an array of strings in JSON but it isn't working.
json:
{
"1": [{
"id": "1",
"title": "test 1",
"galery": { "http://placehold.it/540x540" , "http://placehold.it/540x520"}
}]
}
It's returning me syntax error on "galery" line but I can't figure out what is it
For an array, use:
"galery": ["http://placehold.it/540x540", "http://placehold.it/540x520"]
For named properties, use something like:
"galery": { url1:"http://placehold.it/540x540", url2:"http://placehold.it/540x520" }
Use [ ] for array of images in gallery. { } will expect object (key/value pairs).
You can check valid JSON syntax at http://www.json.org/
Replace the braces with brackets.
{
"1": [{
"id": "1",
"title": "test 1",
"galery": [ "http://placehold.it/540x540" , "http://placehold.it/540x520" ]
}]
}
You have incorrect syntax at two places. Below is the correct one:
{
"1": {
"id": "1",
"title": "test 1",
"galery": ["http://placehold.it/540x540" , "http://placehold.it/540x520"]
}
}
Related
I am implementing a restful service where I am getting the pdf names and their ids from the database in the JSON fromat. Which one of the both the convenient JSON resful service response?
First Option:
{
"results": {
"documentNames": [
"test.pdf",
"ireport-ultimate-guide.pdf",
"sending report.pdf",
"Motor Hour.pdf"
],
"documentds": [
21116,
21117,
21118,
21119
]
}
}
Second Option:
{
"results": {
"21116": "test.pdf",
"21117": "ireport-ultimate-guide.pdf",
"21118": "sending report.pdf",
"21119": "Motor Hour.pdf"
}
}
I would use this "third option": The result is a list of object.
{
"result": [{
"id": "21116",
"filename": "test.pdf"
},
{
"id": "21117",
"filename": "ireport-ultimate-guide.pdf"
},
{
"id": "21118",
"filename": "sending report.pdf"
},
{
"id": "21119",
"filename": "Motor Hour.pdf"
}
]
}
because it better models the object structure.
I would create an entity for each document that contains both name and I'd.
[
{"name": "doc_1", "id": 123},
{"name": "doc_2", "id": 456}
]
I'm trying to conditionally extract the value of an element from the following sample json response:
{
"books": [
{
"title": "book 1 title",
"author": {
"firstName": "author01",
"lastName": "abc"
}
}
{
"title": "book 2 title",
"author": {
"firstName": "author02",
"lastName": "xyz"
}
}
]
}
I want to select the book title where lastName == xyz. Here the expression that I use:
$.books[?(#.author.lastName=='xyz')]
but it returns []
Thanks
Your JSON Path expression is correct, demo:
however there is a problem with your JSON:
{
"books": [
{
"title": "book 1 title",
"author": {
"firstName": "author01",
"lastName": "abc"
}
}, <-----------------------------you need the comma here
{
"title": "book 2 title",
"author": {
"firstName": "author02",
"lastName": "xyz"
}
}
]
}
If your response cannot be resolved to a valid JSON - you will have to use Regular Expression Extractor instead. If it is - double check your JSON Path expression and also worth checking out JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios
Try below expression:
$.books[?(#.author.lastName=='xyz')].title
My object is
{
"name":"Testing",
"id": "hcig_3fe7cb00-e936-11e6-af69-a748c8cc89ad",
"belongsTo": {
"id": "69616d26-c3bb-405c-8c84-c51c091524b2",
"name": "test"
},
"locatedAt": {
"id": "49616d26-c3bb-405c-8c84-c51c091524b2",
"name":"Test"
} }
I want to merge one more object like
"obj":[{
"a": 123
}}
With the help of JSON_MERGE in mysql document store i am able to add object.
But it looks likes
{
"name":"Tester",
"id": "hcig_3fe7cb00-e936-11e6-af69-a748c8cc89ad",
"belongsTo": {
"id": "69616d26-c3bb-405c-8c84-c51c091524b2",
"name": "test"
},
"locatedAt": {
"id": "49616d26-c3bb-405c-8c84-c51c091524b2",
"name":"Test"
},{
"obj":[{
"a": 123
}]
}}
I want my object to be as
{
"name": "Tester",
"id": "hcig_3fe7cb00-e936-11e6-af69-a748c8cc89ad",
"belongsTo": {
"id": "69616d26-c3bb-405c-8c84-c51c091524b2",
"name": "test"
},
"locatedAt": {
"id": "49616d26-c3bb-405c-8c84-c51c091524b2",
"name": "Test"
},
"obj": [{
"a": 123
}]}
Any idea on how to add object as above manner using JSON Functions in mysql ??
Use lodash for a recursive deep copy - https://lodash.com/
lodash.merge(targetObj, sourceObj);
Or if you have programmatic access:
targetObj.obj = sourceObj;
I have a JSON returned by a RESTful API:
{
"0": {
"id": "1484763",
"name": "Name",
"values": {
"0": {
"value": "Peter"
}
}
},
"1": {
"id": "2584763",
"name": "phone",
"values": {
"0": {
"value": "45456456"
}
}
}
}
How do I write a JSONPath that extracts a phone number value? (so in this case, "45456456"). What makes the problem harder, phone number object is not always inside "1" key.
Try this JsonPath which results in phone number 45456456
$..[?(#.name = 'phone')].values.0.value
Basically, you have to apply a filter ?() where name == 'phone' and then use normal json path.
Try the expression in this link
JsonPath expression syntax can be found here.
I have this JSON code:
{
"A": {
"AB": [{
"ABA": "0",
"ABB": "1",
"ABC": "2"
}]
}
}
I need to use a JSONPath expression that returns that JSON with only ABA and ABC attributes. Something like:
{
"A": {
"AB": [{
"ABA": "0",
"ABC": "2"
}]
}
}
So far I manage to extract either one or all attributes. For example
$.A.AB[*]
or
$.A.AB[*].ABA
Is there a way to extract only two?
Thanks
This will work using the Jayway implementation (Java):
$.A.AB[*]['ABB', 'ABA']
and the result for your input would be:
[
{
"ABB" : "1",
"ABA" : "0"
}
]
You can Compare different providers here:
http://jsonpath.herokuapp.com/