marchah / json-mapper-json Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
it goes 2 times in the formatting function
ex:
main: {
path: '$EMPTY',
nested: {
nested_1: '...',
nested_2: '...',
}
}
result:
main: {
nested_1: '...',
nested_2: '...',
}
Hello, I'm having an issue with using the $root keyword. Here is my code:
var source = { "data": { "items": [ {"item": "one"}, {"item": "two"} ] } }
var template = { "query": { path: "data.items", nested: { "item": { path: "$item" } } } }
As a mapping result I will get this:
{ "query": [{ "term":{"item":"one} }, { "term":{"item":"two"} }] }
But when I change in the template 'path: "data.items"' to 'path: "$root.data.items"', I will get this:
{ "query": { "term": [ {"term":{"item":"one}}, {"term":{"item":"two"}} ] } }
So there is a strange behavior of the $root keyword.
Hi, this is an awesome tool to transform data. Thanks for your awesome work!
I am thinking if it's possible to add an option to pass defaultValue to a field. Return the defaultValue rather than throw an error Invalid path xxx
Love this lib. Hope a useful feature can be supported: root/parent/ancestor refs in nested declaration.
jsonMapper.then({
field1: {
field2: {
field3: 'value',
},
},
}, {
'new_field1': {
path: '$root.field1',
formatting: (field1) => {
return field1.field2.field4;
}
},
}).catch((e) => {
console.error(e);
});
Should throw error
TypeError: Cannot read property 'field4' of undefined
But got
TypeError: Cannot read property 'field2' of undefined
Hello, I'm using this lib and I like it. But today I faced an interesting situation.
I have a json from Elasticsearch:
{
"hits": {
"total": 1,
"hits": [
{
"_index": "some_index",
"_type": "some_type",
"_id": "123456",
"_score": 1,
"_source": {
"id": 123456
}
}
]
}
}
And I need to map it into json like this:
{
"type": "some_index/some_type"
"id": "123456"
}
My mapping template:
{
"hits": {
path: "hits.hits",
nested: {
"id": {
path: "_source.id"
},
"type": {
path: "_type",
formatting: (value) => { return value; }
}
}
}
}
So the problem is that I can't get both values from _index and _type at the same time because they are root properties of an array item.
Not the best solution is to wrap each array item like this. And I won't use it
"hits":[
{
"item": {
"_index": "some_index",
"_type": "some_type",
"_id": "123456",
"_score": 1,
"_source": {
"id": 123456
}
}
]
Is it possible to implement a new keyword like "$item" and it will be a whole array item, so it will be possible to grab any number of root properties at the same time.
Hope it's clear :)
Thanks in advance.
Hey,
Is there a way to output an array of one item from a single object?
Input Object:
{ email: "[email protected]" }
Required output:
{ emails: [ { email: "[email protected]" }] }
I have tried the below but its not quite what I need.
{
"emails": {
"path": "$empty",
"nested": {
"email": {
"path": "email"
}
}
}
}
Also this is invalid:
{
"emails": [{
"path": "$empty",
"nested": {
"email": {
"path": "email"
}
}
}]
}
./lib/constants.js
const mongoose = require('mongoose');
However mongoose is declared as a devDependency. Kindly look into this which will cause a build error.
example:
array = ['1', '2', '3'];
formatting: (value) => return value + '_formatted'; },
formatting will be called with 1
, 2
, 3
and ['1_formatted', '2_formatted'. '3_formatted']
Hello.
Sometimes there is a need to get a JSON with a mass of nested fields as a result of mapping like this:
"query": { "constant_score" : { "filter" : { "bool" : { "must" : [ { "term" : {"name" : "foo"}}, { "term" : {"id": 1}} ] } } } }
A source is:
var source = { "data": { "terms": [ {"item": "one"}, {"item": "two"} ] } }
Is there a way to avoid templates like this:
"query": { path: "$root.data", nested: { "constant_score": { path: "$root.data", nested: { "filter" : { path: "$root.data", nested: { "bool": { path: "$root.data", nested: { "must": { path: "$root.data.terms" } } } } } } } } }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.