JSMapr documentation

Hi @Mike Dunker I looked at jsmapr as mentioned in (http://community.apigee.com/articles/1839/converting-between-xml-and-json-what-you-need-to-k.html). Are there any docs explaining js-mapr in more detail?

Solved Solved
0 5 301
1 ACCEPTED SOLUTION

1 vs EACH:

MAP1: perform a mapping on the SINGLE object/item at a specified location in the main object

MAPEACH: perform a mapping on EACH object/item in the ARRAY at the specified location in the main object

FUNC1: call a function with the input being the single object/item at the specified location in the main object, with the return value being used to replace the item

FUNCEACH: call a function for each object/item in the array at the specified location in the main object, with the return value for each object replacing the object in the array

Sorry there aren't more docs right now -- JSMapr is just a side project for me and I'm swamped with other work.

I generally prefer to use mapping instructions instead of custom mapping code, because I find the custom code to be harder to maintain and more likely to get hard to find bugs. I also find it more self-documenting -- I can read the mapping instructions and more easily understand what is being done.

View solution in original post

5 REPLIES 5

Hi @Vineet Bhatia,

There is a decent example in the README at the github site (https://github.com/mdunker/JSMapr, but nothing more at this point.

Please let me know if you find it useful or have suggestions.

Mike

Also, an example proxy that uses it is at https://github.com/apigeecs/soap-js-mapr .

Thanks @Mike Dunker in the mapping approach we make use of response.content.asXML



    var xmlElements = response.content.asXML;

    var i = 0;   

    while(element = xmlElements[i]){     

    i++;     

    arr.push(transformElement(element));   

    }

    function transformElement(element) {
      var obj = new Object();
    obj.name = element.xyzName;
    ...
    }

With JSMapr some of the transformElement code can be done with JSMapr.MAKEARRAY, JSMapr.MOVE, JSMapr.MAPEACH, JSMapr.IFTYPE, JSMapr.MAP1, etc. Is there any document which explains when to use Map1 vs MapEach, etc?

1 vs EACH:

MAP1: perform a mapping on the SINGLE object/item at a specified location in the main object

MAPEACH: perform a mapping on EACH object/item in the ARRAY at the specified location in the main object

FUNC1: call a function with the input being the single object/item at the specified location in the main object, with the return value being used to replace the item

FUNCEACH: call a function for each object/item in the array at the specified location in the main object, with the return value for each object replacing the object in the array

Sorry there aren't more docs right now -- JSMapr is just a side project for me and I'm swamped with other work.

I generally prefer to use mapping instructions instead of custom mapping code, because I find the custom code to be harder to maintain and more likely to get hard to find bugs. I also find it more self-documenting -- I can read the mapping instructions and more easily understand what is being done.

Thanks again @Mike Dunker This definitely helps.