src/record/json-path.js
function setValue (root, path, value) {
  const tokens = tokenize(path)
  let node = root

  let i
  for (i = 0; i < tokens.length - 1; i++) {
    const token = tokens[i]

    if (node[token] !== undefined && typeof node[token] === 'object') {
      node = node[token]
    } else if (typeof tokens[i + 1] === 'number') {
      node = node[token] = []
    } else {
      node = node[token] = {}
    }
  }

  node[tokens[i]] = value
}
function setValue (root, path, value) {
  const tokens = tokenize(path)
  let node = root

  let i
  for (i = 0; i < tokens.length - 1; i++) {
    const token = tokens[i]

    if (node[token] !== undefined && typeof node[token] === 'object') {
      node = node[token]
    } else if (typeof tokens[i + 1] === 'number') {
      node = node[token] = []
    } else {
      node = node[token] = {}
    }
  }

  node[tokens[i]] = value
}
function setValue ( root , path , value ) { const tokens = tokenize ( path ) let node = root let i for ( i = 0 ; i < tokens . length - 1 ; i ++ ) { const token = tokens [ i ] if ( node [ token ] !== undefined && typeof node [ token ] === 'object' ) { node = node [ token ] } else if ( typeof tokens [ i + 1 ] === 'number' ) { node = node [ token ] = [ ] } else { node = node [ token ] = { } } } node [ tokens [ i ] ] = value }
This class allows to set or get specific
values within a json data structure using
string-based paths

@param {String} path A path, e.g. users[2].firstname

@constructor
This class allows to set or get specific values within a json data structure using string - based paths