how could I add document to document in rapidjson - json

I define a template.json file like this:
{ "id":1,
"licence":
{
"province":"BeiJin",
"number":"RB03718"
}
}
define cars.json like this:
{
"cars":[]
}
then load them all
rapidjson::Document car,cars;
loadJson(car, "template.json"); //load the json file from disk
loadJson(cars,"cars.json");
auto & allocator=cars.GetAllocator();
cars.PushBack(car , allocator);
try to get something like this in cars
{
"car": [
{ "id":1,
"licence":
{
"province":"BeiJin",
"number":"RB03718"
}
}
]
}
but as the car document get out of life cycle. element in cars array breaks down.
how could I solve this problem?

Related

How to tie a folder of multiple images to data? GraphQL GatsbyJS

I want to tie a folder with multiple images to my data.
I have some data:
[
{
"title": "data1",
"images" : "./relimages/first-data/",
"cardimages" : "./relimages/main-page-card-images/1.jpg",
},
{
"title": "data2",
"images" : "./relimages/second-data/",
"cardimages" : "./relimages/main-page-card-images/2.jpg",
},
{
"title": "data3",
"images" : "./relimages/third-data/",
"cardimages" : "./relimages/main-page-card-images/3.jpg",
}
]
But when I query them with graphql, I only have a string : "./relimages/first-data"
Although, my cardimages data entry is seen as an image directly.
How can I make my query see that as a folder, instead of just returning the string.
I want this code to work:
<h1>{data.title}</h1>
data.images.edges.map(image => return (<img src={image.node.childImageSharp.fluid.src}/>))
Here's my current GraphQL query:
query flagquery {
allDataRoJson {
edges {
node {
images {
edges {
node {
childImageSharp {
fluid {
src
}
}
}
}
cardimages {
id
childImageSharp {
fluid {
originalImg
}
}
}
}
}
}
}
}
But my image data entry is seen as a string, instead of a folder. Is this possible somehow?
Error is:
Field \"images\" must not have a selection since type \"String\" has no subfields

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.

JSON liquid mapping using payload

I want to access the the below JSON payload :
[
{
"ApplicantContactDetail": [
{
"ApplicantBaseDetails": {
"CATEGORY": "P",
"ULN": "1265847478"
} }
]
}
]
and need output as
{
"Number":2,
"Data":
{
"ResidencyCode":"CATEGORY"
}
}
i need to map CATEGORY in the output from liquid template, may i know the correct syntax for this to achieve.

How do i iterate json object

this json formate have basically two array object so i am lit bit confused that how do i iterate these two object and display separately.
[
{
"todays_birthday":[
{
"member_id":"1",
"member_name":"Subhash Chander Chandna",
"member_number":"490",
"member_dob":"1995-06-30"
},
{
"member_id":"4",
"member_name":"Mrs. Bimla Rani",
"member_number":"500",
"member_dob":"1946-06-30"
}
]
},
{
"tommorow_birthday":[
{
"member_id":"3",
"member_name":"Jagdish Kumar Pahuja",
"member_number":"490",
"member_dob":"1946-07-01"
},
{
"member_id":"5",
"member_name":"Raja Ram",
"member_number":"500",
"member_dob":"1946-07-01"
}
]
}
]
I think your json could be formed as an object with two properties (today_birthdays and tomorrow_birthdays) and inside each property you get the array of birthdays.
Like that:
{
today_birthdays: [
//birthdays
],
tomorrow_birthdays: [
//birthdays
]
}
And so you could iterate through the birthdays, for example, with lodash (in JavaScript):
_(obj.today_birthdays).forEach(function(birthday) {
//use birthday var..
}

Jsonpath for a JSON payload

I have the following JSON payload. I would like to extract the value "value_for_key_attribute_Y" using JSON path expression in a generic manner (i.e. without hard coding any array values like [1]) Any ideas ?
{
"requests":[
{
"event":[
{
"parameter":"parameter_key_A",
"event":"event_key_A",
}
],
"data":[
{
"id":"id_xyz",
"payload_data":[
{
"key":"key_attribute_X",
"value":"value_for_key_attribute_X",
},
{
"key":"key_attribute_Y",
"value":"value_for_key_attribute_Y",
}
]
}
]
}
]
}
Something like this should work for you.
$.requests[*].data[*].payload_data[?(#.key_path == 'key_attribute_Y')].value